0
help ,i am running in c++,it says string is not declare,and i wanted to use only these header file,not iostream
#include <stdio.h> #include<string.h> int main() { string s; scanf("%s",s); printf("%s",s); return 0; }
3 Respuestas
+ 3
string keyword is not present in c (stdio.h headers)
use a character array instead
eg: char s[20];
+ 2
you can use printf("%s", s.c_str()), but scanf can only deal with char arrays and s.c_str() wont work because it returns a const char * and points to an empty char array. so in the end you have to use Sreejith‘s answer if you want to use scanf.
the answer to this stackoverflow post also has a solution https://stackoverflow.com/questions/20165954/read-c-string-with-scanf