Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中的字符串格式+;_C++_Alignment - Fatal编程技术网

C++ C+中的字符串格式+;

C++ C+中的字符串格式+;,c++,alignment,C++,Alignment,我想以下面的格式显示字符串输出 Bill Robinson Gross Amount: ............ $3575.00 Federal Tax: ............. $ 536.25 State Tax: ............... $ 125.13 这是我当前的源代码 < left << setw(width) << setfill ('.') << "Gross Amount : " << showbase &

我想以下面的格式显示字符串输出

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
可以这样做吗? 为了防止区域设置出现任何问题,我删除了
put\u 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;
    }
}
#包括
#包括
#包括
#包括
使用名称空间std;
结构数据{
数据(字符串_s,浮点_f):s(_s),f(_f){
字符串s;
浮动f;
};
int main(){
const int width=36;
载体d;
d、 推回(数据(“总额:,3575.00”);
d、 向后推(数据(“联邦税:”,536.25));
d、 推回(数据(“州税:”,125.13));

请提供您现在拥有的源代码。您对输出的哪一部分有问题?您尝试了什么?这是如何工作的?您的实际输出不是预期的输出,而是什么?FWIW,
#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;
    }
}