473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

s.erase()

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

s.erase();

Does this make the string empty?

Thanks.
Oct 21 '05 #1
8 2884
Jason Heyes wrote:
I have a std::string 's' and I write:

s.erase();

Does this make the string empty?


Depends on how you define 'empty'.

Stefan
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Oct 21 '05 #2
>
I have a std::string 's' and I write:

s.erase();

Does this make the string empty?


Depends on how you define 'empty'.


s.empty()
Oct 21 '05 #3
Jason Heyes wrote:
I have a std::string 's' and I write:

s.erase();

Does this make the string empty?


Depends on how you define 'empty'.

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
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Oct 21 '05 #4
>

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

s.erase();

Does this make the string empty?
Depends on how you define 'empty'.

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>


I would prefer a direct answer.
Oct 21 '05 #5
Jason Heyes wrote:
>I have a std::string 's' and I write:
>
> s.erase();
>
>Does this make the string empty?
>

Depends on how you define 'empty'.

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>


I would prefer a direct answer.


Can't be that hard to figure out...
$ ./strempty
s is empty
Stefan
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Oct 21 '05 #6
>

I would prefer a direct answer.


Can't be that hard to figure out...
$ ./strempty
s is empty


I'm trying to conserve brain cells.
Oct 21 '05 #7
Jason Heyes wrote:
I would prefer a direct answer.


Can't be that hard to figure out...
$ ./strempty
s is empty


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.

Oct 21 '05 #8
Rolf Magnus wrote:
Jason Heyes wrote:

I would prefer a direct answer.
Can't be that hard to figure out...
$ ./strempty
s is empty


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.


Thanks, Rolf...
Stefan
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Oct 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: s | last post by:
Here is a snippet of my code: <code> list< MyClass * >outgoing_pool; MyClass* GetWaitingObject(string freq) { MyClass *temp_ptr = NULL; list<MyClass*>::iterator i;
5
by: Angus Leeming | last post by:
Dinkumware's online STL reference http://tinyurl.com/3es52 declares std::map's overloaded erase member functions to have the interface: map::erase iterator erase(iterator where); iterator...
7
by: jose luis fernandez diaz | last post by:
Hi, Is this right any stl container (vector, deque, list, . . .)? typedef vector container; int main() { container<int> c1;
26
by: Pieter Thysebaert | last post by:
Hello, I've got a question conerning erasing key-value pairs from a std::map while iterating over it. According to the STL docs, erasing an element in a map invalidates all iterators pointing...
3
by: jose luis fernandez diaz | last post by:
Hi, Erase elements while iterating on a map don't invalidate the iterator except the erased one, so the program below: (1) #include <map> int main()
20
by: Tom van Stiphout | last post by:
I'm about to write a function like below, which I'm going to call a lot of times. So I care about possible memory leaks. I think whether I should use Erase or not depends on whether Split creates...
8
by: olanglois | last post by:
Hi, I was asking myself to following question. What is better to erase an element from a STL map: calling (option #1) size_type erase(const key_type& k) or calling (option #2)
11
by: moleskyca1 | last post by:
Hi, I know if you call erase when you iterate through map you will crash. Ex: map<int,doublem; // insert something for ( map<int, double>::iterator i = m.begin(); i != m.end(); i++ ) if (...
6
by: catphive.lists | last post by:
Is there a way to call erase(iter) on a list without invalidating the iterator? Can I make a copy of an iterator and then move forward the original without moving the copy? I'm aware of the...
3
by: subramanian100in | last post by:
Consider vector<stringv; If we call, v.erase(v.end()) this invokes undefined behaviour. But, if we call
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.