my problem is the following: I would like to align an output text to the total right of my output shell when executing. I can not use the standard std::setw() and std::right manipulator, because I wish the output is always at the right boundary, no matter how much large is the shell.
Is there a way to achieve this?
As commented by @Angew, output is a stream, so it doesn't have a total right. To achieve the goal, you can simply get the width of the shell first, and then use setw() and right:
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
int width = csbi.dwSize.X;
string str = "string you want to print";
cout << right << setw(width) << str << endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With