cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Strings library : string : string::empty
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Strings library
char_traits
classes:
· string
global functions:
· getline
· operator+
· operator<<
· operator>>
· comparison operators
· swap
string
string::string
member constants:
· string::npos
member functions:
· string::append
· string::assign
· string::at
· string::begin
· string::capacity
· string::clear
· string::compare
· string::copy
· string::c_str
· string::data
· string::empty
· string::end
· string::erase
· string::find
· string::find_first_not_of
· string::find_first_of
· string::find_last_not_of
· string::find_last_of
· string::get_allocator
· string::insert
· string::length
· string::max_size
· string::operator+=
· string::operator=
· string::operator[]
· string::push_back
· string::rbegin
· string::rend
· string::replace
· string::reserve
· string::resize
· string::rfind
· string::size
· string::substr
· string::swap

-

string::empty public member function
bool empty ( ) const;

Test if string is empty

Returns whether the string is empty, i.e. whether its size is 0.

This function does not modify the content of the string in any way. To clear the content of the string, member clear can be used.

Parameters

none

Return Value

true if the string size is 0, false otherwise.

Example

// string::empty
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string content;
  string line;
  cout << "Please introduce a text. Enter an empty line to finish:\n";
  do {
    getline(cin,line);
    content += line + '\n';
  } while (!line.empty());
  cout << "The text you intorduced was:\n" << content;
  return 0;
}

This program reads the user input line by line and stores it into string content until an empty line is introduced.

Basic template member declaration

( basic_string<charT,traits,Allocator> )
bool empty ( ) const;

See also

string::clear Clear string (public member function)
string::size Return length of string (public member function)
string::length Return length of string (public member function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us