2017-02-13 26 views
-2

嗨首先这是我的计划,我想我的程序中所有的输出隔离在在C运输及工务局局长问题++

下面是我的程序的输出现在我想使输出为全行在年龄和部分:

#include<iostream> 
#include <iomanip> 
using namespace std; 
struct student { 
string fullname[200]; 
string course[200]; 
int age[200]; 
}; 
student p1; 
main() 
{ 
    int input; 
    cout<<"How many Student do you like to Add:"; 
    cin>>input; 
    for(int i=0; i!=input; i++) 
    { 
     cout<<"----------Input #"<<i+1<<"----------"<<endl; 
     cout<<"Enter Name: "; 
     cin.ignore(); 
     getline (cin,p1.fullname[i]); 
     cout<<"Enter Age: "; 
     cin>>p1.age[i]; 
     cout<<"Enter Section: "; 
     cin>>p1.course[i]; 
    } 

    cout<<"\n\n----------------- List of Student that is 19 Above -----------------"<<endl; 
    cout<<"\nFull Name:"<<setw(20)<<"Age:"<<setw(20)<<"Section:"<<endl; 

    for(int i=0; i!=input; i++) 
    { 
     if(p1.age[i] >= 19) 
     { 
     cout<<p1.fullname[i]<< setfill(' ') <<setw(20) <<p1.age[i]<< setfill(' ') <<setw(20)<<p1.course[i]<<endl;  
     } 
    } 
    system("PAUSE"); 
} 
+1

欢迎。请看[问]。 –

回答

1

你需要,你想写前场申请setfillsetw。并且您还需要将其应用于fullname

cout << setfill(' ') 
    << setw(20) << p1.fullname[i] 
    << setw(20) << p1.age[i] 
    << setw(20) << p1.course[i] 
    << endl; 
+0

如果填充字符不变,只需要应用一次'setfill' –

+0

@ M.M好点。在我的答案中,我只是复制粘贴了原始代码,因此是双setfill。我现在只是把它减少到了一个'setfill'。 –