clear
描述 (Description)
它会删除字符串的内容,该字符串将变为空字符串。
声明 (Declaration)
以下是std :: string :: clear的声明。
void clear();
C++11
void clear() noexcept;
参数 (Parameters)
没有
返回值 (Return Value)
没有
异常 (Exceptions)
如果抛出异常,则字符串中没有变化。
例子 (Example)
在下面的示例中,std :: string :: clear。
#include <iostream>
#include <string>
int main () {
char c;
std::string str;
std::cout << "Please type some lines of text. Enter a start (*) to finish:\n";
do {
c = std::cin.get();
str += c;
if (c=='\n') {
std::cout << str;
str.clear();
}
} while (c!='*');
return 0;
}
样本输出应该是这样的 -
Please type some lines of text. Enter a start (*) to finish:
sairam.krishna *