다음을 통해 공유


basic_string::empty

Tests whether the string is contains characters or not.

bool empty( ) const;

Return Value

true if the string object contains no characters; false if it has at least one character.

Remarks

The member function is equivalent to size == 0.

Example

// 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;
}

Output

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

The string object str2 is empty.

Requirements

Header: <string>

Namespace: std

See Also

Concepts

basic_string Class

basic_string Members