Aligning text to the right in the C++ console

雨燕双飞 提交于 2020-07-23 06:27:13

问题


How do I format my console output so that it's aligned to the right in C++?


回答1:


Use the manipulator flag std::right

Example

or

This works...

#include<iostream>
using std::cout;
using std::endl;


#include<iomanip>
using std::setw;

int main(){

 int x = 12345;

 cout << "Blah Blah Blah" << endl << setw(80) <<  x << endl;

 system("pause");

 return 0;
}


来源:https://stackoverflow.com/questions/3824696/aligning-text-to-the-right-in-the-c-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!