我正在制作一个饮料机程序,我希望所有的价格都排在一起。
有没有办法告诉编译器从行首写价格 X 个空格,而不是在发布饮料名称后添加空格?
int main()
{
const int arrsize = 5;
Drinks arr[arrsize] = {
{"Cola",.75,20},
{"Root Beer",.75,20},
{"Lemon-Lime",.75,20},
{"Grape Soda",.80,20},
{"Cream Soda",.80,20},
};
for (;;){
cout << "Please select a drink: "<<endl;
for (int i = 0; i < arrsize; i++){
cout << (i+1)<<". "<< arr[i].DrinkName;
cout << setw(10) << setfill(' ')<< right <<fixed << arr[i].DrinkCost<<endl;
}
cout <<"6. Quit";
break;
}
return 0;
}
我想要的是它看起来像这样:
Please select a drink:
1. Cola 0.75
2. Root Beer 0.75
3. Lemon-Lime 0.75
4. Grape Soda 0.80
5. Cream Soda 0.80
6. Quit
但它看起来像这样:
Please select a drink:
1. Cola 0.75
2. Root Beer 0.75
3. Lemon-Lime 0.75
4. Grape Soda 0.80
5. Cream Soda 0.80
6. Quit