c++ - "gets() was not declared in this scope" error -


with following code, "gets() not declared in scope" error:

#include <iostream> #include <string.h> using namespace std;  int main() {     // string str[]={"i boy"};     string str[20];`     gets(str);     cout<<*str;     return 0; } 

as gets() c style function, if need include in c++ code need include header file called stdio.h , can pass c style string gets() function not c++ string class. after slight modification in code becomes:

#include <iostream> #include <string.h> #include "stdio.h" using namespace std;  int main() {  // string str[]={"i boy"};  char str[20];`   gets(str);   printf("%s",str);  return 0; } 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -