C++ String 库 - empty
描述
它返回字符串是否为空(即其长度是否为 0)。
声明
以下是 std::string::empty 的声明。
bool empty() const;
C++11
bool empty() const noexcept;
参数
none
返回值
如果字符串长度为 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

