String concatenation in c++
Why this code outputs "Hi!This!" if user input is "This is string" string s; cin>>s; s="Hi!" + s + "!"; cout<<s;
If you replace cin >> s: with getline(cin, s); it also supports full names.
cin extraction always considers spaces (whitespaces, tabs, new-line...) as terminating the value being extracted, and thus extracting a string means to always extract a single word, not a phrase or an entire sentence. To get an entire line from cin, there exists a function, called getline, that takes the stream (cin) as first argument, and the string variable as second.