Connecting Tech Pros Worldwide Help | Site Map

std::string

  #1  
Old July 22nd, 2005, 07:00 PM
conf
Guest
 
Posts: n/a
How to know if a std::string has empty content or not? Thanks!


  #2  
Old July 22nd, 2005, 07:00 PM
Siemel Naran
Guest
 
Posts: n/a

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()) {
...
}


  #3  
Old July 22nd, 2005, 07:00 PM
Sharad Kala
Guest
 
Posts: n/a

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


  #4  
Old July 22nd, 2005, 07:00 PM
Siemel Naran
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
_efficiently_ obtain n-th word from a std::string Jacek Dziedzic answers 11 May 13th, 2007 07:25 PM
std::map<int, std::string[2]> problems Erik Wikström answers 19 July 23rd, 2005 06:18 AM
Read text file into std::string. Jason Heyes answers 22 July 23rd, 2005 06:15 AM
Quick std::string question Christopher Benson-Manica answers 11 July 22nd, 2005 07:27 AM
class String : public std::string {}; ???? Angus Leeming answers 10 July 19th, 2005 06:24 PM