33,311
社区成员
发帖
与我相关
我的任务
分享
//
#include "stdafx.h"
#include "stdio.h"
int main()
{
char str1;
char str2[10];
puts("please enter a character ");
str1=getchar(); //获取字符
putchar(str1); //输出获得的字符
puts("please enter string");// 提示输入字符串
gets(str2); //从输入流中抓取字符串
puts(str2); //输出获得的字符串
return 0;
}
------ 已启动生成: 项目: character, 配置: Debug Win32 ------
1> character.cpp
1>c:\users\i love u\desktop\新建文件夹\character\character\character.cpp(14): error C4996: 'gets': This function or variable may be unsafe. Consider using gets_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\tmqq\vc\include\stdio.h(261) : 参见“gets”的声明
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
刚才在MSDN Library上查了一下gets_s
是gets的更安全版本,还想请教您一下,gets为什么不安全