VS2013 or similar resolve in 2017: error C4996: 'scanf': This function or variable may be unsafe question

Used to the previous scanf () function, sudden use scanf_s () function is more or less a little uncomfortable, so here to tell you about the use or benefit scanf_s it!

1, scanf_s format control function in addition to the string format specification, if there are other characters, these characters must enter the same character in the corresponding position on the input data.

      例如:scanf_s("%d,%d,%d",&a,&b,&c);

      When the input data, should be inputted 1,2,3; comma between 123 "," can not be omitted, not before 123

       When the input value, the value to be inserted between the two spaces or other delimiter character are required to distinguish between a plurality of values. However, if the case exemplified above occurs, you can only use the format control character string corresponding to the character character.

       As the degree of your mother said: a lot with "_s" suffix function is to make the original function is more secure, and passing a parameter value related to the size, to avoid a reference to an element that does not exist, sometimes hackers can use the original black insecurity out of the system. The ratio: char d [20]; written scanf_s ( "% s", d , 20); is correct, there are parameters that make 20 improve accuracy.

2, but still used to input scanf, provide here the easiest way to let you return to your own habits among!

      :( The first step must be set) in the project in the Project Properties -> Configuration Properties -> C / C ++ -> Preprocessor -> pre-defined -> click on the button (V) -> Edit, enter: "_ CRT_SECURE_NO_WARNINGS" to ok

Published 62 original articles · won praise 93 · views 120 000 +

Guess you like

Origin blog.csdn.net/GenuineMonster/article/details/88115793