www.delorie.com/archives/browse.cgi | search |
From: | "bowman" <bowman AT montana DOT com> |
Newsgroups: | comp.os.msdos.djgpp |
References: | <HhOCsDAf$YN3EwuI AT dunvegan1 DOT demon DOT co DOT uk> <0jzu8AArMaN3EwpJ AT dunvegan1 DOT demon DOT co DOT uk> <UTmZ2.2585$mW3 DOT 16026 AT newsfeed DOT slurp DOT net> <37374ACB DOT BA48C9DF AT unb DOT ca> |
Subject: | Re: Converting numbers to strings |
Lines: | 22 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 5.00.2014.211 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2014.211 |
Message-ID: | <7mMZ2.420$l%4.2872@newsfeed.slurp.net> |
Date: | Mon, 10 May 1999 20:11:17 -0600 |
NNTP-Posting-Host: | 208.4.224.10 |
X-Trace: | newsfeed.slurp.net 926388739 208.4.224.10 (Mon, 10 May 1999 21:12:19 CDT) |
NNTP-Posting-Date: | Mon, 10 May 1999 21:12:19 CDT |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Endlisnis <s257m AT unb DOT ca> wrote in message news:37374ACB DOT BA48C9DF AT unb DOT ca... > > ostrstream ostr; > > for (int i=0; i<20; i++) { > > ostr << "pic" << setfill('0') << setw(3) << i << ".bmp" << ends; > > cout << "filename = " << ostr.str() << endl; > > ostr.seekp(0); > What is the "seekp" there for? ostr grows with each iteration of the loop. If you remove the 'ends' you can watch it. With the 'ends', ostr.str() will always return 'pic000.bmp'. Using seekp(0) resets the pointer, causing each iteration to overwrite the previous one, and display correctly. The example is a little contrived; in many cases, you would use the ostrstream once, and it would go out of scope, and wouldn't hang around collecting garbage.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |