std::string

Discussion in 'C++' started by conf, Aug 18, 2004.

  1. conf

    conf Guest

    How to know if a std::string has empty content or not? Thanks!
     
    conf, Aug 18, 2004
    #1
    1. Advertisements

  2. conf

    Siemel Naran Guest

    "conf" <> wrote in message
    news:TXAUc.220081$OB3.10255@bgtnsc05-

    > How to know if a std::string has empty content or not? Thanks!


    bool isempty = string.empty();

    or

    if (string.empty()) {
    ...
    }

    You can also do

    if (string.size()) {
    ...
    }
     
    Siemel Naran, Aug 18, 2004
    #2
    1. Advertisements

  3. conf

    Sharad Kala Guest

    "conf" <> wrote in message
    news:TXAUc.220081$...
    > How to know if a std::string has empty content or not? Thanks!


    std::string has an empty member function to check for empti-ness.
    if (s.empty())
    {
    //...
    }

    -Sharad
     
    Sharad Kala, Aug 18, 2004
    #3
  4. conf

    Siemel Naran Guest

    "Sharad Kala" <> wrote in message

    > std::string has an empty member function to check for empti-ness.
    > if (s.empty())


    I was thinking, the name is a bit unfortunate. It's a verb, so indicates
    that it will empty out 's'. I think s.isempty() would have been nicer :).
     
    Siemel Naran, Aug 18, 2004
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias =?ISO-8859-1?Q?K=E4ppler?=

    std::string::push_back vs. std::string::operator+=

    Matthias =?ISO-8859-1?Q?K=E4ppler?=, Nov 22, 2004, in forum: C++
    Replies:
    2
    Views:
    4,495
    Jonathan Mcdougall
    Nov 23, 2004
  2. Peter Jansson
    Replies:
    5
    Views:
    7,005
    Ivan Vecerina
    Mar 17, 2005
  3. Jim Langston

    std::string = char* + std::string

    Jim Langston, Jun 30, 2005, in forum: C++
    Replies:
    9
    Views:
    602
    Jim Langston
    Jul 2, 2005
  4. Vinu
    Replies:
    4
    Views:
    555
    Jim Langston
    Jul 7, 2005
  5. Fei Liu
    Replies:
    9
    Views:
    706
  6. Jeffrey Walton
    Replies:
    10
    Views:
    1,274
    Mathias Gaunard
    Nov 26, 2006
  7. Christopher Pisz
    Replies:
    11
    Views:
    677
    James Kanze
    Jan 13, 2008
  8. Dwight Army of Champions
    Replies:
    0
    Views:
    539
    Dwight Army of Champions
    Apr 20, 2010
Loading...