Results 1 to 4 of 4

Thread: cout problem

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default cout problem

    Hi, I'm printing some values in a loop with this code:
    Qt Code:
    1. cout << "\tOut" << y << "= " <<output<< " " ;
    2. cout << "\terr = " << error << "\t" << " sq_err = " << _serrv<< " ";
    3. cout << "OK";
    4. cout << "\n";
    5. // I know this can be done in a line...
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //output
    2. Out0= 0.9474925 err = 0.05250749 sq_err = 0.001378518 OK
    3. Out0= 0.6843882 err = 0.3156118 sq_err = 0.04980541
    4. Out0= 0.8848782 err = 0.1151218 sq_err = 0.006626516 OK
    5. Out0= 0.7979639 err = 0.2020361 sq_err = 0.0204093 OK
    6. Out0= 0.9102138 err = 0.08978618 sq_err = 0.004030779 OK
    To copy to clipboard, switch view to plain text mode 
    Why does any sq_err appear not tabulated (\t seems hans't effect)
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: cout problem

    It has an effect, just the tabulator is one character after the end of the previous text. Look that for "err" rows which are one digit longer "sq_err" fields are tabulated correctly. Either pad (or fill) the err field if it's shorter or calculate the tabulation yourself and add another \t if needed.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: cout problem

    Maybe you could use setw() instead of tabulators?
    J-P Nurmi

  4. #4
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: cout problem

    Tabs will tab to the next tab column, which are eight spaces wide. If you look at your output, you will see that you are off eight spaces. This is a common problem when trying to line up columns with \t characters.

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.