Open jokerkeny opened 5 years ago
https://github.com/Mooophy/Cpp-Primer/blob/master/ch03/ex3_5b.cpp In line 13, for (string buff; cin >> buff; str += (str.empty() ? "" : " ") + buff); why should it check whether str is empty? Could it be empty?.
str is empty at first. When you input some words, There should be a blank space between each two words, so it's neccessary check whether str is empty, If not ,insert " ".
https://github.com/Mooophy/Cpp-Primer/blob/master/ch03/ex3_5b.cpp In line 13, for (string buff; cin >> buff; str += (str.empty() ? "" : " ") + buff); why should it check whether str is empty? Could it be empty?.