Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何格式化输出_C++_Function_Setw - Fatal编程技术网

C++ 如何格式化输出

C++ 如何格式化输出,c++,function,setw,C++,Function,Setw,我希望有一个干净的格式化输出,但结果并不像我想要的那样干净。下面是我的函数,它显示输出,后面是输出。我正在使用Dev-C++。谢谢你的帮助 void student::show(string name, int age, double GPA) { cout<<name<<setw(7) <<age<<setw(7) <<GPA <<setw(7) <<endl; } ****************

我希望有一个干净的格式化输出,但结果并不像我想要的那样干净。下面是我的函数,它显示输出,后面是输出。我正在使用Dev-C++。谢谢你的帮助

void student::show(string name, int age, double GPA)
{
  cout<<name<<setw(7) <<age<<setw(7) <<GPA <<setw(7) <<endl;

}



******************output*******************************************



Timaya     24   2.65
 albert     29   2.43
zamounda     27   3.94
charles     26   2.78
 moumou     33   2.39
francois     24   3.07
   john     20   2.59
   papa     21   2.67
   peti     29   3.65
francoise     26   3.76
  iness     28   2.65
  elise     35   2.76
------------------------------------
-------------------------------------
GPA of the class:2.94
void student::show(字符串名称、整数年龄、双GPA)
{

cout由于
setw
设置下一个输出值的宽度,而不是上一个输出值的宽度,因此应在格式化项目之前将
setw
调用移动到:

cout << setw(20) << name << setw(7) << age << setw(7) << GPA << endl;
cout