scanf_s
是微软专用的。它的头文件是stdio.h
,但在GCC中不存在。
用于从标准输入流中读取格式化数据。这些版本的scanf,scanf_s,_scanf_l,wscanf,_wscanf_l都有安全增强功能。
而 Ideone使用GCC
,因此你只会得到undefined reference to scanf_s
的错误信息。
大多数情况下,你可以在基于Windows的编译器中找到这个函数,比如
Visual Studio 2008和Microsoft .NET 2010。
int scanf_s(
const char *format [,
argument]...
);
char s[10];
scanf_s("%9s", s, 10);
In the case of characters, one may read a single character as follows:
char c;
scanf_s("%c", &c, 1);
在读取非空终止字符串的多个字符时,使用整数作为宽度规格和缓冲区大小。
char c[4];
scanf_s("%4c", &c, 4); // not null terminated
scanf_s
不是微软的非标准用法吗? - Paul R