1234567891011121314151617181920
// string::clear #include <iostream> #include <string> int main () { 1 char c; 2 std::string str; 3 std::cout << "Please type some lines of text. Enter a dot (.) to finish:\n"; 4 do { 5 c = std::cin.get(); 6 str += c; 7 if (c=='\n') 8 { 9 std::cout << str; 10 str.clear(); 11 } 12 } while (c!='.'); 13 return 0; 14}
123
std::string str = "Car"; str += 's'; std::cout << str; // prints "Cars"
operator+=