Tag Archives: error: ‘gets’ was not declared in this scope; did you mean ‘fgets’?

[Solved] error: ‘gets’ was not declared in this scope; did you mean ‘fgets’?

Cause of problem

Gets () is no longer supported by the C + + compiler of the submission platform,

Solution:

Method 1: use C language instead

However, the C speech compiler is not affected. Change the header file to C language format and use the C speech compiler to pass.

Method 2: use cin.getline instead

/* Read a line (can contain spaces) until the end of the newline character
 /* Store the first num-1 characters in the array a and end with the character c */
cin.getline(a, num, c);

be careful:

You can also pass in the third parameter C, which ends with ‘\0’ by default

If num is greater than the number of characters read in, it is directly stored in the whole line of string, and then the end of character c is added at the end