basic_string::empty

文字列の文字が含まれているかどうかをテストします。

bool empty( ) const;

戻り値

String オブジェクトの文字が含まれている場合true ; 少なくとも 1 文字がある場合 false

解説

このメンバー関数は サイズ == 0 と同じです。

使用例

// basic_string_empty.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main() {
   using namespace std;

   bool b1, b2;

   string str1 ("Hello world");
   cout << "The original string object str1 is: " << str1 << endl;
   b1 = str1.empty();
   if (b1)
      cout << "The string object str1 is empty." << endl;
   else
      cout << "The string object str1 is not empty." << endl;
   cout << endl;

   // An example of an empty string object
   string str2;
   b2 = str2.empty();
   if (b2)
      cout << "The string object str2 is empty." << endl;
   else
      cout << "The string object str2 is not empty." << endl;
}

出力

The original string object str1 is: Hello world
The string object str1 is not empty.

The string object str2 is empty.

必要条件

ヘッダー: の <文字列>

名前空間: std

参照

関連項目

basic_string クラス