什么是得到()相当于C11? [英] What is gets() equivalent in C11?

查看:124
本文介绍了什么是得到()相当于C11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 cplusplus.com

最近C标准的修订(2011年)明确了
  从规范中删除此功能。

The most recent revision of the C standard (2011) has definitively removed this function from its specification

该功能是在C ++ pcated德$ P $(截至2011标准,如下
  C99 + TC3)。

The function is deprecated in C++ (as of 2011 standard, which follows C99+TC3).

我只是想知道什么是替代获得()在C11标准?

I just wanted to know what is the alternative to gets() in C11 standard?

推荐答案

在C11 获得已被 gets_s 具有以下声明:

In C11 gets has been substituted by gets_s that has the following declaration:

char *gets_s(char *str, rsize_t n);

此功能将最多读 N-1 标准输入字符到 * STR 。这是为了避免固有的获得的缓冲区溢出漏洞。功能与fgets 也是一种选择。从 HTTP://en.cp$p$pference.com/w/c/io/gets

This function will read at most n-1 chars from stdin into *str. This is to avoid the buffer overflow vulnerability inherent to gets. The function fgets is also an option. From http://en.cppreference.com/w/c/io/gets:

获得()函数不执行边界检查,因此该功能非常容易受到缓冲区溢出攻击。它不能安全使用(除非程序制约有什么可以读取标准出现的环境中运行)。出于这个原因,该功能已经在C11标准在第三更正C99标准pcated和完全删除德$ P $。 与fgets() gets_s()是推荐替代。

The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflow attacks. It cannot be used safely (unless the program runs in an environment which restricts what can appear on stdin). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard. fgets() and gets_s() are the recommended replacements.

切勿使用获得()

由于 gets_s 中的扩展,标准的定义,只是可选的实施,你应该使用编写的程序与fgets 来代替。如果你使用与fgets 标准输入你的计划也将编制在早期版本的C.但是要记住的差异行为:当 gets_s 已经阅读 N-1 字符它保持阅读,直到一个新行或端值的文件达到,丢弃的投入。所以,用 gets_s 你总是在阅读一整行,哪怕只是它的一部分可以在输入缓冲区中返回。

Given that gets_s is defined in an extension to the standard, only optionally implemented, you should probably write your programs using fgets instead. If you use fgets on stdin your program will also compile in earlier versions of C. But keep in mind the difference in the behavior: when gets_s has read n-1 characters it keeps reading until a new line or end-of-file is reached, discarding the input. So, with gets_s you are always reading an entire line, even if only a part of it can be returned in the input buffer.

这篇关于什么是得到()相当于C11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆