Do "setw(offset) " BEFORE cout ?
-
OK, I can do search and replace "cout<<" with "cout<< setw(offset)<< " to shift the output start column to console at offset. BUT anybody has an idea / hack how to PRESET "cout" ?
int offset = 10; setw(offset); // preset to offset , but this does not work , obviously cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; offset += 10; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
-
OK, I can do search and replace "cout<<" with "cout<< setw(offset)<< " to shift the output start column to console at offset. BUT anybody has an idea / hack how to PRESET "cout" ?
int offset = 10; setw(offset); // preset to offset , but this does not work , obviously cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; offset += 10; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
-
OK, I can do search and replace "cout<<" with "cout<< setw(offset)<< " to shift the output start column to console at offset. BUT anybody has an idea / hack how to PRESET "cout" ?
int offset = 10; setw(offset); // preset to offset , but this does not work , obviously cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; offset += 10; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
Usually when doing that sort of thing its easier to swing to ANSI which is semi portable on Windows and Linux consoles and you can have colours. Still cant set it global pre calls. An example
printf("\x1B[%d;%df\x1B[31;40mRed line at 10,20\n", 10, 20);
printf("\x1B[37;40m");In vino veritas
-
OK, I can do search and replace "cout<<" with "cout<< setw(offset)<< " to shift the output start column to console at offset. BUT anybody has an idea / hack how to PRESET "cout" ?
int offset = 10; setw(offset); // preset to offset , but this does not work , obviously cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; cout << setw(offset ) << "Test " << endl; offset += 10; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl; cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
-
Unfortunately, neither the
setw
manipulator nor the width[^] method is persistent. However, you may find workarounds here: c++ - "Permanent" std::setw - Stack Overflow[^]. -
Usually when doing that sort of thing its easier to swing to ANSI which is semi portable on Windows and Linux consoles and you can have colours. Still cant set it global pre calls. An example
printf("\x1B[%d;%df\x1B[31;40mRed line at 10,20\n", 10, 20);
printf("\x1B[37;40m");In vino veritas
Leon, I am getting used to using cout, despite of its irrational behaviour. In my main project I went overboard with debugging colouring scheme and it sort of works. I just started the "client" part of the project and reusing a class from my main project where cout colouring and cout lines work just as expected. In derived project - no coloring, cout lines have extra line feed and I am getting non printable characters to boot. Just another bug to find. BTW I am finding out this setw does not always work....
-
Leon, I am getting used to using cout, despite of its irrational behaviour. In my main project I went overboard with debugging colouring scheme and it sort of works. I just started the "client" part of the project and reusing a class from my main project where cout colouring and cout lines work just as expected. In derived project - no coloring, cout lines have extra line feed and I am getting non printable characters to boot. Just another bug to find. BTW I am finding out this setw does not always work....