empty
描述 (Description)
它返回字符串是否为空(即其长度是否为0)。
声明 (Declaration)
以下是std :: string :: empty的声明。
bool empty() const;
C++11
bool empty() const noexcept;
参数 (Parameters)
没有
返回值 (Return Value)
如果字符串长度为0,则返回true,否则返回false。
异常 (Exceptions)
如果抛出异常,则字符串中没有变化。
例子 (Example)
在下面的示例中,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