LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2005, 03:38 AM   #1
gecoool
Member
 
Registered: Feb 2005
Location: Romania
Distribution: Fedora 2
Posts: 38

Rep: Reputation: 15
ostringstream width


Hello people ;-)

I wish to find out if there is a way to "keep" the width of an ostringstream after it was set with width() call. That is if I set the width to 2 (i.e) after first << operation, the width of the stream goes back to the default value.

ostringstream off;
off.width(2);
off.fill('0');

int k=3;

off<<3; //this one produces off.str()="03"
int j=2;
off<<j; //now i get "032"; //and i would like to get 0302, without repeted call to width and fill ... If this is possible, please advise me.

Last edited by gecoool; 12-07-2005 at 03:39 AM.
 
Old 12-08-2005, 12:49 PM   #2
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
I don't think so, i found this website with the following note:

NOTE -- With the exception of the field width, all format parameter settings are permanent. The field width parameter is reset after each use
 
Old 12-08-2005, 12:53 PM   #3
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
oh, but by the way, you can set the width in the ostring.

#include <iostream>
#include <iomanip>

ostringstream off;

off.fill('0');

off<<std::setw(2)<<3<<std::setw(2)<<2;

will set the width for both statements.
not the iomanip include, the std::setw() function is defined there.
 
Old 12-09-2005, 02:02 AM   #4
gecoool
Member
 
Registered: Feb 2005
Location: Romania
Distribution: Fedora 2
Posts: 38

Original Poster
Rep: Reputation: 15
Thankz sirclif ;-)

The relevant answer for me is the first one: ironically the width property is the only one non-permanent for the stream. What I intended was to avoid making the call of off.width() or another one (i.e. setw) every time. It is actually a piece of "critical" code ... in terms of speed. I dropped the idea of using streams and fell back to old char array ;-), which is fastest. Anyway I must thank you for your time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
emacs width line jrdioko Linux - Software 14 07-10-2009 11:48 AM
Does ostringstream or stringbuf have a buffer max? SCOSWriter Programming 6 08-18-2005 12:48 PM
Controlling the band width…. shahg_shahg Linux - Networking 1 12-20-2004 02:31 PM
get maximum browser width Boby Programming 3 07-16-2004 04:01 PM
Name Width in apache im1crazyassmofo Linux - Networking 1 07-28-2003 03:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration