我想以下面的格式显示字符串输出。
Bill Robinson
Gross Amount: ............ $3575.00
Federal Tax: ............. $ 536.25
State Tax: ............... $ 125.13
这是我目前的源代码
< left << setw(width) << setfill ('.') << "Gross Amount : " << showbase << right << setw(currncy) << put_money(grossAmount) <<endl
但是我得到了这个输出
Gross Amount : ..................$2,344.00
Edaral Tax : ......................$351.60
State Tax : ........................$82.04
答案 0 :(得分:0)
可以这样做吗?
为了防止语言环境出现任何问题,我删除了put_money
函数。
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
struct data {
data(string _s, float _f) : s(_s), f(_f) {}
string s;
float f;
};
int main() {
const int width = 36;
vector<data> d;
d.push_back(data("Gross Amount: ", 3575.00));
d.push_back(data("Federal Tax: ", 536.25));
d.push_back(data("State Tax: ", 125.13));
cout<<"Bill Robinson"<<endl;
for (data a : d) {
cout << setfill ('.') << a.s << setw(width - a.s.size()) << "$" << setfill (' ') << setw(7) << fixed << setprecision(2) << (a.f) <<endl;
}
}
抱歉原始代码。