std::string

S

Siemel Naran

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

Sharad Kala

conf said:
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
 
S

Siemel Naran

Sharad Kala said:
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 :).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top