🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #755

Cannot reset an ostrstream back to start position

#755
From: Nicolas Reimen
Date: Sat, 07 Apr 2001 10:55
46 lines
1915 bytes
This code :

#include <string>
#include <iostream>
#include <strstream>

using namespace std;

int main(int argc, char* argv[])
{
 ostrstream ss;

 ss << "foo "<< 1234 << ends;
 printf("%s\n", ss.str());
 printf("tellp %d\n", ss.tellp());
 ss.seekp(0);
 printf("tellp %d\n", ss.tellp());
 ss << "bar "<< 5678 << ends;
 printf("%s\n", ss.str());

 return 0;
}

should ( from my naive point of view ) produce the following output:

foo 1234
tellp 9
tellp 0
bar 5678

But, what I get is :

foo 1234
tellp 9
tellp 0
foo 1234

The insert pointer is correctly set back to 0, it seems, but
the ostrtream still does not want to overwrite what is
already in the buffer.

Can anyone help ?

PS: I am using MS VC++6 and I found the advice to
use seekp in msdn, but without more details or
an example :-(
Technical Details
Message-ID: <9amrrc$1v3r$1@news5.isdnet.net>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!freenix!isdnet!isdnethub!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114592,bbe7da431f112f2b,start
X-Google-Attributes: gid114592,public
X-Google-Thread: fdcad,bbe7da431f112f2b,start
X-Google-Attributes: gidfdcad,public
X-Google-Thread: 109fba,bbe7da431f112f2b,start
X-Google-Attributes: gid109fba,public
X-Google-ArrivalTime: 2001-04-07 04:02:07 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!freenix!isdnet!isdnethub!not-for-mail
From: "Nicolas Reimen" <Nicolas.reimen@acm.org>
Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,fr.comp.lang.c++
Subject: Cannot reset an ostrstream back to start position
Date: Sat, 7 Apr 2001 12:55:23 +0200
Lines: 50
Message-ID: <9amrrc$1v3r$1@news5.isdnet.net>
NNTP-Posting-Host: r73m203.cybercable.tm.fr
X-Trace: news5.isdnet.net 986641068 64635 195.132.73.203 (7 Apr 2001 10:57:48 GMT)
X-Complaints-To: abuse@isdnet.net
NNTP-Posting-Date: 7 Apr 2001 10:57:48 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700