-1
我想用C++在表中輸入數據。 我需要輸入不同的列。問題是,當我使用cin時,它跳到下一行,而不是繼續在同一行。在C++中輸入數據表
這裏是我使用的代碼:
string itemname;
int amount;
float price;
cout << setprecision(2);
cout << fixed;
cout << left << setw(30) << string(30, '-') << endl;
cout << left << setw(10) << "Itemname" << setw(10) << right << "Amount" << setw(10) << right << "Price" << endl;
cin >> left >> setw(10) >> itemname >> setw(10) >> right >> amount >> setw(10) >> right >> price;
有什麼事我可以比CIN這樣做使用其他?
是的,但是當我使用這個我不會得到適當的欄目,有沒有什麼辦法,我可以做到這一點? –
@ParthSindhu列僅由空格分隔嗎?然後我的答案中的代碼將很好地*讀*輸入。標準輸入(在C或C++中)不是字段方式。底層代碼和程序(終端模擬器和內核和緩衝區)讀取*行*,然後簡單地解析行中的字段。 –