在C++;安慰 我如何格式化控制台输出,以便它与C++中的右对齐?

在C++;安慰 我如何格式化控制台输出,以便它与C++中的右对齐?,c++,text-alignment,C++,Text Alignment,使用操纵器标志std::right 或 这很有效 #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;

使用操纵器标志
std::right

这很有效

#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;
}
#包括
使用std::cout;
使用std::endl;
#包括
使用std::setw;
int main(){
int x=12345;

不能使用操纵器标志
std::right

这很有效

#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;
}
#包括
使用std::cout;
使用std::endl;
#包括
使用std::setw;
int main(){
int x=12345;

不能在文本前面放置一组空格,使其与80列控制台的右边缘对齐吗?:)在文本前面放置一组空格,使其与80列控制台的右边缘对齐吗?:)@Ben Voigt,谢谢,伙计,这就是为什么在两个解决方案选项之间存在OR的原因。请在评论之前阅读。啊,好的:“初始化时,标准流中的adjustfield标志设置为right”示例链接不再工作,请在帖子中内联解决方案或更新链接。@Ben Voigt,谢谢dude,这就是为什么在两个解决方案选项之间有一个or。请先阅读再评论。啊,好的:在初始化时的标准流中,adjustfield标志设置为right“示例链接不再工作,在post中内联解决方案或更新链接。