How can I read the input as string (with spaces) and deal with it as array of chars?
I’ve not used C++ for many years, but this should get you started:
#include <iostream> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { for (int i=0; i<str.size(); i++) printf("%c\n", str[i]); } return 0; }
thanks so much
You can use gets method in C programs to read string with space characters. #include <stdio.h> int main() { char str[20]; gets(str); printf("%s", str); return 0; }