gets, gets_s
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <stdio.h> 中定义
|
||
char *gets( char *str ); |
||
char *gets_s(char *str, rsize_t n); |
(C11 起)(可选) | |
1)
读取到的字符数组指出,stdin,直到找到一个换行符或文件结束时,
str
。 A原文:
Reads stdin into the character array pointed to by
str
until a newline character is found or end-of-file occurs. A空字符的最后一个字符数组读入后立即写.
原文:
null character is written immediately after the last character read into the array.
2)
从n-1在最stdin字符读取到数组中指出,
str
,直到新行字符,文件结束的条件,或读取错误。一个空字符后立即写的最后一个字符读入数组,如果没有字符被读取,或str[0].原文:
Reads at most n-1 characters from stdin into the array pointed to by
str
until new-line character, end-of-file condition, or read error. A null character is written immediately after the last character read into the array, or to str[0] if no characters were read.@ @如果
n
是零或大于RSIZE_MAX,一个空字符写入str[0],但该函数读取并丢弃字符stdin,直到新行字符,文件结束的条件,或读取错误.原文:
@@ If
n
is zero or is greater than RSIZE_MAX, a null character is written to str[0] but the function reads and discards characters from stdin until new-line character, end-of-file condition, or read error.@ @如果
n-1
字符被读取,stdin继续阅读和丢弃的字符,直到新行字符,文件结束的条件,或读取错误.原文:
@@ If
n-1
characters have been read, continues reading and discarding the characters from stdin until new-line character, end-of-file condition, or read error.@ @的
gets_s
功能的延伸和是可选的。它保证只有__STDC_LIB_EXT1__定义.原文:
@@ The
gets_s
function is an extension and is optional. It is guaranteed to be present only if __STDC_LIB_EXT1__ is defined.目录 |
[编辑] 参数
str | - | 字符串被写入
|
[编辑] 返回值
str
成功,NULL其他方式[编辑] 注释
gets()
函数不执行边界检查,因此这个功能是非常容易受到缓冲区溢出攻击。它不能被安全地使用(除非该程序运行的环境中的限制可以出现在什么stdin
)。出于这个原因,该功能已经被废弃在第三更正的C99标准和C11标准完全删除。 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()
.[编辑] 另请参阅
stdin,文件流或缓冲区的读取格式的输入 原文: reads formatted input from stdin, a file stream or a buffer (函数) | |
得到一个字符串从一个文件流 原文: gets a character string from a file stream (函数) | |
将一个字符串写入一个文件流 原文: writes a character string to a file stream (函数) | |
C++ documentation for gets
|