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. Advertising

  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. Advertising

  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. Advertising

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.

Share This Page