C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ String empty()

C++ String empty()

此函数检查字符串是否为空。函数返回布尔值true或false。

语法

考虑字符串str。语法为:
str.empty();

参数

此函数不包含任何参数。

返回值

它返回布尔值视情况而定,取值为0或1、

示例1

#include<iostream>
    using namespace std;
     int main()
    {
      string str1;
     if(str1.empty())
    cout<<"String is empty";
    else
    cout<<"String is not empty";
    return 0;}
输出:
String is empty
此示例显示如何通过使用empty()函数检查字符串是否为空。

示例2

#include<iostream>
using namespace std;
int main()
{
    string str1="Hello lidihuo";
            if(str1.empty())
    cout<<"String is empty";
    else
    cout<<"String is not empty";
    return 0;
}
输出:
String is not empty
此示例通过使用empty()函数检查字符串是否为空。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4