How do I flush a strstream buffer so that the next time I call .str() I
get back an empty string?
Thanks 10 11030
Just put an empty string in it.
#include <cstdlib>
#include <sstream>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
stringstream s;
s << "Blah";
cout << "1: " << s.str() << "." << endl;
s.str("");
cout << "2: " << s.str() << "." << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Zachary Turner wrote: How do I flush a strstream buffer so that the next time I call .str() I get back an empty string?
Do you really need to use the old char* based streams? In a stringstream,
(std::string-based stream) you simply do
ss.str(""); ss.clear();
and it's fine. The old (strstream) most likely won't work like that.
V
Yeah I actually meant stringstream. I don't use strstream. Anyway
funny that the solution is so trivial. I looked in MSDN help for ages
(using Visual C++) and it honest to god just doesn't mention that
overload of the str() function. And I type so fast I've just never
noticed the intellisense pop up when i type the ( to see that it has an
overloaded version. I've been wondering about that question for longer
than I care to admit but it never affected me to the point I had to ask
on a forum. Now I feel dumb, hehe.
"Zachary Turner" <di***********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com... Yeah I actually meant stringstream. I don't use strstream. Anyway funny that the solution is so trivial. I looked in MSDN help for ages (using Visual C++) and it honest to god just doesn't mention that overload of the str() function.
Really? From the help file with my VC++v6.0:
basic_stringstream
template <class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_stringstream : public basic_iostream<E, T> {
public:
explicit basic_stringstream(ios_base::openmode mode = ios_base::in |
ios_base::out);
explicit basic_stringstream(const basic_string<E, T, A>& x,
ios_base::openmode mode = ios_base::in | ios_base::out);
basic_stringbuf<E, T, A> *rdbuf() const;
basic_string<E, T, A>& str();
void str(const basic_string<E, T, A>& x);
};
Looks like two overloads to me. :-)
-Mike
"Mike Wahler" <mk******@mkwahler.net> wrote... [...] basic_string<E, T, A>& str(); void str(const basic_string<E, T, A>& x);
Looks like two overloads to me. :-)
Are you kiddin'? One name is written aaaall the way to the right
and the other - aaaaalll the way to the left. Overload my foot!...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:pY********************@comcast.com... "Mike Wahler" <mk******@mkwahler.net> wrote... [...] basic_string<E, T, A>& str(); void str(const basic_string<E, T, A>& x);
Looks like two overloads to me. :-)
Are you kiddin'? One name is written aaaall the way to the right and the other - aaaaalll the way to the left. Overload my foot!...
:-)
Hey, don't laugh! I must have stared at that code for 2-3 minutes before I
spotted that first overload. Which is why, I think, my boss always formats
his code so that the identifiers (i.e., "str" in this case) line up in a
single column. It's too weird for me, but at least he can find the member
names quickly.
-Howard
"Howard" <al*****@hotmail.com> wrote in message
news:6W*******************@bgtnsc05-news.ops.worldnet.att.net... "Victor Bazarov" <v.********@comAcast.net> wrote in message news:pY********************@comcast.com... "Mike Wahler" <mk******@mkwahler.net> wrote... [...] basic_string<E, T, A>& str(); void str(const basic_string<E, T, A>& x);
Looks like two overloads to me. :-) Are you kiddin'? One name is written aaaall the way to the right and the other - aaaaalll the way to the left. Overload my foot!... :-) Hey, don't laugh! I must have stared at that code for 2-3 minutes before
I spotted that first overload. Which is why, I think, my boss always
formats his code so that the identifiers (i.e., "str" in this case) line up in a single column. It's too weird for me, but at least he can find the member names quickly.
Long, long ago, in a galaxy far far away, I was told that
essential to programming is attention to detail. I've
never forgotten that. :-)
-Mike
Mike Wahler wrote: [...] Long, long ago, in a galaxy far far away, I was [...]
Ah, that's where you're from :-)
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:fm*******************@newsread1.mlpsca01.us.t o.verio.net... Mike Wahler wrote: [...] Long, long ago, in a galaxy far far away, I was [...]
Ah, that's where you're from :-)
No, I just went to school there. Helluva commute. ;-)
-Mike
Mike Wahler wrote: "Victor Bazarov" <v.********@comAcast.net> wrote in message news:fm*******************@newsread1.mlpsca01.us.t o.verio.net...
Mike Wahler wrote:
[...] Long, long ago, in a galaxy far far away, I was [...]
Ah, that's where you're from :-)
No, I just went to school there. Helluva commute. ;-)
What? No dorm? Must be a really good school if it was worth
the commute :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: TaiwanNoWhere |
last post by:
// case 1
int Option = 0;
for(;;)
{
cin >> Option;
switch(Option)
{
case 1:
|
by: Chris Mantoulidis |
last post by:
Let's say I have this:
std::string s1;
std::cin >> s1;
This will read s1 from cin until it finds a space (or a newline,
whichever comes first).
Okay this works. But when I want to continue...
|
by: Kyle Kolander |
last post by:
I posted this in response to a previous thread but have not gotten any
replies back... Hopefully someone has an answer?
From looking at sections 27.7.3.2 and 27.7.1.2 of the standard, it appears...
|
by: piotrek |
last post by:
Hi
I have a problem with http headers.
Iam creating:
private HttpWebRequest request = null;
and:
request = (HttpWebRequest)WebRequest.Create(server);
|
by: AD |
last post by:
Hi
I am trying to read elements of a vector from console (cin) in two
steps ie, read a list of numbers from cin. Sort these. Then read from
cin again and append in same vector.
...
|
by: Àî°× |
last post by:
hi all:
I want erase a stringstream' content for input new data to it.
example:
std::stringstream stm;
stm<<"this is a string";
std::cout<<stm.str();
// here print:this is a string
|
by: Ville Vainio |
last post by:
I tried to clear a list today (which I do rather rarely, considering
that just doing l = works most of the time) and was shocked, SHOCKED
to notice that there is no clear() method. Dicts have it,...
|
by: Russell Warren |
last post by:
I'm guessing no, since it skips down through any Lock semantics, but
I'm wondering what the best way to clear a Queue is then.
Esentially I want to do a "get all" and ignore what pops out, but I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |