- 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++ 字符串库 - 空
描述
它返回字符串是否为空(即长度是否为0)。
宣言
以下是 std::string::empty 的声明。
bool empty() const;
C++11
bool empty() const noexcept;
参数
没有任何
返回值
如果字符串长度为 0,则返回 true,否则返回 false。
例外情况
如果抛出异常,则字符串不会发生任何变化。
例子
在下面的 std::string::empty 示例中。
#include <iostream>
#include <string>
int main () {
std::string content;
std::string line;
std::cout << "Please introduce a text. Enter an empty line to finish:\n";
do {
getline(std::cin,line);
content += line + '\n';
} while (!line.empty());
std::cout << "The text you introduced above was:\n" << content;
return 0;
}
示例输出应该是这样的 -
Please introduce a text. Enter an empty line to finish: sairamrkshna mammahe The text you introduced above was: sairamrkshna mammahe
字符串.htm