However, the codes came from a tutorial in youtube named thenewboston. It perfectly works in the tutorial video but when I copied it, something went wrong. The codes are to print name.
wow. But as what my friend told me, string was used before c++ was updated recently and string was changed into char. String doesn't accept spaces(space bar) because it always causes error so it was only designed for just a word (string = 1 word).
as what my friend told me, string was used before c++ was updated recently and string was changed into char
Your friend is mistaken. Strings can hold any sequence of characters. As for spaces, your friend is probably confusing what a string can hold vs. what operator>>(istream&, string &) will do:
1 2
string str;
cin >> str; // operator reads one word into str
You can also read a whole line into a string with getline()