我想讀一個文件,其中有AC米蘭球員的名字和他們的出生日期。我想在兩個對齊的列中顯示。我試圖使用setw()並離開,但結果不是我想要的。這是我用來讀取和打印的代碼:對齊列輸出C++
void read(char filename[]){
fstream mio_file;
char c;
bool start_name = true;
bool start_date = true;
mio_file.open(filename, ios_base::in | ios_base::binary);
mio_file.read(&c, sizeof(char));
while(!mio_file.eof()){
if(c >= 'A' && c <= 'z' && start_name){
cout << endl << "Name : ";
start_name = false;
start_date = true;
}
if(c >= '0' && c <= '9' && start_date){
cout << setw(25) << left << "Date of birth : ";
start_date = false;
start_name = true;
}
cout << c;
mio_file.read(&c, sizeof(char));
}
mio_file.close();
}
這是輸出:
這是輸出,我想:
setw(...)名稱 – Sopel
@RickAstley:在此處使用正確。把這當作一個教訓,讓你做出清晰的表述! –