I the below mentioned program:
string s;
cout<<"Enter a string:";
gets(s);
I expect my input to be of the form: “Hilton Hotels”.
On using gets, I get the following error:
error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘char*’ for argument ‘1’ to ‘char* gets(char*)’
I can not use “cin” as I want my input to consist of space and special characters like ‘_’ etc, also I want my delimiter to be ‘enter’. Is there some other way…or please be kind enough in correcting the error.
getsisn’t very c++ (it’s for compatibility with C). Use this:Also, look at
std::ios::skipwsand<iomanip>for whitespace handling options