string::clear

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

#include <iostream>
#include <string>

using namespace std;

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

 
posted @ 2019-12-23 17:41  MoonXu  阅读(211)  评论(0编辑  收藏  举报