user-0 提问: 是Scanf()函数的错吗？

回复:
user: user-1
content: 引用 12 楼 wtsuipingyigao 的回复:[quote=引用 8 楼 zhao4zhong1 的回复:] #pragma warning(disable:4996) 这是从哪本书上学到的？[/quote] MSDN98 mk:@MSITStore:C:\MSDN98\98VS\2052\vccore.chm::/html/_predir_warning.htm warning #pragma warning( warning-specifier : warning-number-list [,warning-specifier : warning-number-list...] )  #pragma warning( push[ , n ] )  #pragma warning( pop )  Allows selective modification of the behavior of compiler warning messages.  The warning-specifier can be one of the following.  Warning-specifier Meaning  once Display the specified message(s) only once.  default Apply the default compiler behavior to the specified message(s).  1, 2, 3, 4 Apply the given warning level to the specified warning message(s).  disable Do not issue the specified warning message(s).  error Report the specified warnings as errors.    The warning-number-list can contain any warning numbers. Multiple options can be specified in the same pragma directive as follows:  #pragma warning( disable : 4507 34; once : 4385; error : 164 )  This is functionally equivalent to:  #pragma warning( disable : 4507 34 )  // Disable warning messages                                       //  4507 and 34. #pragma warning( once : 4385 )        // Issue warning 4385                                       //  only once. #pragma warning( error : 164 )        // Report warning 164                                       //  as an error.  For warning numbers greater than 4699, those associated with code generation, the warning pragma has effect only when placed outside function definitions. The pragma is ignored if it specifies a number greater than 4699 and is used inside a function. The following example illustrates the correct placement of warning pragmas to disable, and then restore, the generation of a code-generation warning message:  int a; #pragma warning( disable : 4705 ) void func() {     a; } #pragma warning( default : 4705 )  The warning pragma also supports the following syntax:  #pragma warning( push [ ,n ] )  #pragma warning( pop )  Where n represents a warning level (1 through 4).   The pragma warning( push ) stores the current warning state for all warnings. The pragma warning( push, n) stores the current state for all warnings and sets the global warning level to n.   The pragma warning( pop ) pops the last warning state pushed onto the stack. Any changes made to the warning state between push and pop are undone. Consider this example:  #pragma warning( push ) #pragma warning( disable : 4705 ) #pragma warning( disable : 4706 ) #pragma warning( disable : 4707 ) // Some code #pragma warning( pop )   At the end of this code, pop restores the state of all warnings (including 4705, 4706, and 4707) to what it was at the beginning of the code.  When you write header files, you can use push and pop to ensure that changes to warning states made by the user do not prevent your headers from compiling properly. Use push at the beginning of the header and pop at the end. Suppose, for example, you have a header that does not compile cleanly at warning level 4. The following code changes the warning level to 3, then restores the original warning level at the end of the header:  #pragma warning( push, 3 ) // Declarations/ definitions #pragma warning( pop )

user: user-2
content: 不推荐使用了

user: user-1
content: #pragma warning(disable:4996)

user: user-0
content: 引用 8 楼 zhao4zhong1 的回复:#pragma warning(disable:4996) 这是从哪本书上学到的？

user: user-0
content: 引用 3 楼 braveboyny 的回复:我的错!!!你谁呀!你犯不了这么高档的错...

user: user-3
content: 加上 #define _CRT_SECURE_NO_WARNINGS 在开头就好了

user: user-4
content: 你的警告级别应该是/W4 定义宏就可以关闭这个警告：  #define _CRT_NO_WARNINGS  #include <stdio.h>

user: user-5
content: ANSI C中没有scanf_s(),只有scanf()，scanf()在读取时不检查边界，所以可能会造成内存泄露。所以vc++2005/2008中提供了scanf_s(),在最新的VS2013中也提供了scanf_s()。在调用时，必须提供一个数字以表明最多读取多少位字符。  引用 楼主 wtsuipingyigao 的回复:说明：下面是程序源代码，编译器——VS2013（使用scanf时VS2010能正确运行)，VS2013中语法规则提高了？必须使用scanf_s了？ #include<stdio.h> #include<string.h> int main(void) { 	char name1[11], name2[11]; 	int count;  	printf("Please enter two names!\n"); 	//fflush(stdin); 	count = scanf_s("%s %s", name1,name2); 	//count = strlen(gets_s(name1,11)); 	printf("I read the %d names:%s and %s\n", count, name1, name2); 	return 0; }

user: user-6
content: 只是不推荐使用

user: user-7
content: 有溢出的风险，不过你disable掉这个警告。

user: user-8
content: 我的错!!!

user: user-9
content: 看看vs2013有什么选项可以用以前的？

user: user-10
content: 只是不推荐使用了。