string::clear

void clear() noexcept;
功能:把string对象置为空

#include <iostream>
#include <string>

using namespace std;

int main()
{
char c;
string str;
cout << "please enter text ";
do{
c = cin.get();
str += c;
if(c == ' ')
{
cout << str;
str.clear();
}
}while(c != '.');
return 0;
}

 
原文地址:https://www.cnblogs.com/xpylovely/p/12085044.html