C++ empty()函数

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 <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 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.

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Empty string(空字符串)是指内容长度为0的字符串。它可以通过单引号 '' 或双引号 "" 来表示。 在编程和数据库中,Empty string与Null(空值)是不同的概念。空值表示没有被赋予具体数值或数据的状态,而Empty string是一个字符串类型,它可以被赋予具体的空字符串值。 在设计表结构时,一般建议避免使用Null或空值,而是将String类型的字段默认设置为Empty string,即空字符串 '',将Int类型的字段默认设置为0。这样可以使数据更加清晰、规范,并且方便进行数据处理和比较。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Navicat mysql 建表字段 默认值、empty string、空白、NULL 的区别](https://blog.csdn.net/zx1323/article/details/80416852)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [MySQL默认值NULL、空值、Empty String的区别,如何选择?](https://blog.csdn.net/haibo0668/article/details/119211690)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WeSiGJ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值