string::clear

void clear () noexcept; 
Function: the string object as null

#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;
}

 

Guess you like

Origin www.cnblogs.com/xpylovely/p/12085044.html