int main()
{
string str;
cout<<"string";
cin >> str;
cout << "The size of str is " << str.size() << " characters.\n";
return 0;
}
should be very simple right well everything works except if the user enters a space it stops. EX "Dog Toy" should be 7 but I keep getting three. Please help
cout<< "Character Counter"<<endl<<endl;
cout << "string: ";
getline( cin, userinput );
cout<<"Total Number of Charactars= " << userinput.length();
I have the #include <string> at the top. See anything wrong its like I have put no cin it just never wait on user input it moves on. BTW userinput is a sting i declared. Mine looks exactly like your except names and output
cin stops reading at a white space, {" ", ' ', \n, \t,...} any type of white space.
if you need to read something that could have spaces (string) use getline(cin, var);
and if your reading in a character array use cin.getline(var, sizeof(var));