Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4596024
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:03:24+00:00 2026-05-21T23:03:24+00:00

I recently was bitten by the fact that ios_base::width and/or the setw manipulator have

  • 0

I recently was bitten by the fact that ios_base::width and/or the setw manipulator have to be reset with every item written to the stream.

That is, you must do this:

while(whatever)
{
    mystream << std::setw(2) << myval;
}

Rather than this:

mystream.width(2);
while(whatever)
{
    mystream << myval;
}

Ok, fine.

But does anyone know why this design decision was made?
Is there some rationale that I’m missing, or is this just a dark corner of the standard?

Other stream formatting modifiers (as mentioned in the linked SO question) are ‘sticky’, while setw is not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:03:25+00:00Added an answer on May 21, 2026 at 11:03 pm

    The way i see it is : You can always do something like below if you want it to be applied uniformly.

    int width =2;
    while(whatever)
    {
        mystream << std::setw(width) << myval;
    }
    

    but if it was sticky as you mention:

    mystream.width(2);
    while(whatever)
    {
        mystream << myval;
    }
    

    and if i wanted a different width every line I have to keep setting width.

    So essentially both approaches are almost the same, and i would like or dislike them depending on what i am doing now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an old (around 5 years) enterprise application that I manage. Recently we
I have been bitten by something unexpected recently. I wanted to make something like
Encoding issues are among the one topic that have bitten me most often during
recently I have been trying to add a link that allows people to delete
Recently I noticed (after others have extended the project) that the compile time significantly
I've recently been bitten by the javascript:void(null); bug in my hrefs when applied to
I've recently been bitten by the (way too commmon in my opinion) gotcha of
Recently I've found how to add a link to an item in Visual Studio
Recently, I was writing a class in which I discovered that I could reduce
Recently the PHP manual started showing the following warning on every mysql function page:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.