How gets () is a C-style function, so if you need to include it in your C ++ code, you need to include the stdio.h header file, and in addition, you can only pass the ac-style string to the gets () function not C + + string class. Therefore, after a small modification of your code, it becomes:
#include <iostream>
#include <string.h>
#include "stdio.h"
using namespace std;
int main()
{
char str[20];`
gets(str);
printf("%s",str);
return 0;
}
source
share