Solve the error reporting problem of using gets() in C++ under VS2019

1. Problem description

scanf()Both functions and gets()functions can be used to input strings, but there are differences in functionality.

getsSpaces can be accepted, and will be automatically added after the end'\0'

scanfEncountering a space , carriage return and Tab will consider the input to be over, so it cannot receive spaces, and it will be automatically added after the end'\0'

But in C++, using getswill report an error:

insert image description here

2. Solutions

After searching for information later, I found out that VS2015 does not support getsit , and it becomes gets_s, and the array name cannot be written alone in the brackets behind, and the number in the array needs to be added. The usage is as follows:

gets_s(words, STLEN);

At this point, the compilation will not report an error:

insert image description here

Guess you like

Origin blog.csdn.net/m0_63325890/article/details/127918882