- C 标准库
- C 标准库
- C++ 标准库
- C++ 库 - 主页
- C++ 库 - <fstream>
- C++ 库 - <iomanip>
- C++ 库 - <ios>
- C++ 库 - <iosfwd>
- C++ 库 - <iostream>
- C++ 库 - <istream>
- C++ 库 - <ostream>
- C++ 库 - <sstream>
- C++ 库 - <streambuf>
- C++ 库 - <原子>
- C++ 库 - <复杂>
- C++ 库 - <异常>
- C++ 库 - <功能>
- C++ 库 - <限制>
- C++ 库 - <语言环境>
- C++ 库 - <内存>
- C++ 库 - <新>
- C++ 库 - <数字>
- C++ 库 - <正则表达式>
- C++ 库 - <stdexcept>
- C++ 库 - <字符串>
- C++ 库 - <线程>
- C++ 库 - <元组>
- C++ 库 - <类型信息>
- C++ 库 - <实用程序>
- C++ 库 - <valarray>
C++ 字符串库 - 清晰
描述
它会删除字符串的内容,使其变为空字符串。
宣言
以下是 std::string::clear 的声明。
void clear();
C++11
void clear() noexcept;
参数
没有任何
返回值
没有任何
例外情况
如果抛出异常,则字符串不会发生任何变化。
例子
在下面的 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 *
字符串.htm