C++ empty()函数
发布日期:2021-05-08 03:54:58 浏览次数:19 分类:精选文章

本文共 830 字,大约阅读时间需要 2 分钟。

文章目录

empty()

NULL空就返回1,其他返回0

bool empty() const noexcept;

Test if string is empty
Returns whether the string is empty (i.e. whether its length is 0).

This function does not modify the value of the string in any way. To clear the content of a string, see string::clear.

Parameters

none

Return Value

true if the string length is 0, false otherwise.

Example

// string::empty#include 
#include
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 was:\n" << content; return 0;}

Edit & Run

This program reads the user input line by line and stores it into string content until an empty line is introduced.

上一篇:使用spring maill发送邮件
下一篇:Elasticsearch介绍及与项目整合

发表评论

最新留言

很好
[***.229.124.182]2025年04月11日 09时00分31秒