Connecting Tech Pros Worldwide Forums | Help | Site Map

std::string

conf
Guest
 
Posts: n/a
#1: Jul 22 '05
How to know if a std::string has empty content or not? Thanks!



Siemel Naran
Guest
 
Posts: n/a
#2: Jul 22 '05

re: std::string


"conf" <conf@soft.com> wrote in message
news:TXAUc.220081$OB3.10255@bgtnsc05-
[color=blue]
> How to know if a std::string has empty content or not? Thanks![/color]

bool isempty = string.empty();

or

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

You can also do

if (string.size()) {
...
}


Sharad Kala
Guest
 
Posts: n/a
#3: Jul 22 '05

re: std::string



"conf" <conf@soft.com> wrote in message
news:TXAUc.220081$OB3.10255@bgtnsc05-news.ops.worldnet.att.net...[color=blue]
> How to know if a std::string has empty content or not? Thanks![/color]

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

-Sharad


Siemel Naran
Guest
 
Posts: n/a
#4: Jul 22 '05

re: std::string


"Sharad Kala" <no__spam.sharadk_ind@yahoo.com> wrote in message
[color=blue]
> std::string has an empty member function to check for empti-ness.
> if (s.empty())[/color]

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 :).


Closed Thread