ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.