[c++]Question about setw

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #16
    Originally posted by Simonius
    weaknessforcats am I doing something wrong in my code because I can't find anything about a stringstream only being capable of being used once.
    You can reuse a stringstream, however in doing so you need to reset it first before you try to use it call the method

    stringstream::c lear();

    on your instance of the class before trying to reuse it.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #17
      Originally posted by whodgson
      Doesn`t `setw` set the width of the column to which the data is printed?; whereas \t sets the width of the column separating the 2 data columns.
      e.g.
      cout<<setw(3)<< i<<"\t"<<setw(5 )<<i*i<<"\n"; //might keep the data columns tidier.
      \t does not set the width to anything, it is a character and how it is handled normally depends on the terminal to which you send it.

      Commonly the terminal moves the output cursor to the next column multiple of 8.

      Comment

      Working...