s.erase()

J

Jason Heyes

I have a std::string 's' and I write:

s.erase();

Does this make the string empty?

Thanks.
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

Jason said:
I have a std::string 's' and I write:

s.erase();

Does this make the string empty?

Depends on how you define 'empty'.

Stefan
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

Jason said:
s.empty()

Try this to check yourself:

<code>

#include <string>
#include <iostream>

int main()
{
std::string s("Hello World");
s.erase();
std::cout << "s is " << (s.empty() ? "empty" : "not empty") << std::endl;
return 0;
}

</code>


Stefan
 
J

Jason Heyes

Try this to check yourself:

<code>

#include <string>
#include <iostream>

int main()
{
std::string s("Hello World");
s.erase();
std::cout << "s is " << (s.empty() ? "empty" : "not empty") <<
std::endl;
return 0;
}

</code>

I would prefer a direct answer.
 
R

Rolf Magnus

Jason said:
I'm trying to conserve brain cells.

You have a big problem either with your brain or with your computer if
compiling and executing a small test program destroys a significant amount
of your brain cells.
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

Rolf said:
Jason Heyes wrote:




You have a big problem either with your brain or with your computer if
compiling and executing a small test program destroys a significant amount
of your brain cells.

Thanks, Rolf...


Stefan
 

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

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top