scanf 不能用?!'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

 「學習路上總有需多無法預期的阻礙來打擊你,

                試著探索它,並找出方法解決,現在來上網找找吧。」

                                                                給自己的一段話

執行以下程式卻跑出一段錯誤與一段警告

警告 C6031 已忽略傳回值: 'scanf'。

錯誤        C4996 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.


#include <iostream>

int main()

{

puts("HI!...");

char name[20];

puts("Enter something: ");

scanf("%19s", name);

printf("Oh yeah! %s.\n\nYou are best!\n", name);

}


後來查找後只要在宣告前增加一段#define _CRT_SECURE_NO_WARNINGS

就可正常執行!




留言