The way to do it right in C ++ is to use std :: string.
#include<iostream> #include<string> .... std::string r; getline(cin, r); std::cout << r <<std::endl;
For truncated input (with corresponding defined and entered values).
while(cin.peek() != EOF && i < len) { cin >> arr[i]; ++i; }
After that, you will want to do something to clear the buffer and not leave the rest of the line sitting on the input stream if you plan to do other things with it.
source share