< Previous | Contents | Next >

Using the empty() Member

Function

The empty() member function returns a bool valuetrue if the string object is empty and false otherwise. I use empty() in the following code:

if (phrase.empty())

{

cout << "\nThe phrase is no more.\n";

}

Because phrase is equal to the empty string, phrase().empty returns true, and the screen displays the message, The phrase is no more.