Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.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++ 将stdio.h程序转换为iostream_C++_C_Syntax - Fatal编程技术网

C++ 将stdio.h程序转换为iostream

C++ 将stdio.h程序转换为iostream,c++,c,syntax,C++,C,Syntax,这是我的主要模块。我有一些外部模块 int main(void) { char ln[15+1]; char fn[10+1]; float fed,state,ssi; float g,h,p,d,n; InputEmployeeData(&ln[0],&fn[0],&h,&p,&d); // call 3.3 CalculateGross(h,p, &g); // call 3.4 co

这是我的主要模块。我有一些外部模块

int main(void)
{
    char ln[15+1];
    char fn[10+1];
    float fed,state,ssi;
    float g,h,p,d,n;

    InputEmployeeData(&ln[0],&fn[0],&h,&p,&d); // call 3.3
    CalculateGross(h,p, &g); // call 3.4
    computeTaxes(g,d,ADDR(fed),ADDR(state),ADDR(ssi)); // call 3.5
    n = g-fed-state-ssi-d;
    printf("  Fed   =   %8.2f\n",fed);
    printf("  State =   %8.2f\n",state);
    printf("  SSI   =   %8.2f\n",ssi);
    printf("  Net   =   %8.2f\n",n);
    while(getchar() != '\n'); // flush(stdin)
    return 0;
使用iostream的main.cpp

cout << "  Fed   =   %8.2f\n" << fed;
cout << "  State =   %8.2f\n" << state;
cout << "  SSI   =   %8.2f\n" << ssi;
cout << "  Net   =   %8.2f\n" << n;
 cin.sync();
//while(getchar() != '\n'); 
// flush(stdin)
return 0;
{
    cout << " Enter the name ==> ";
    cin >> *firstname >> *lastname;
    cout <<" Enter the hours and payrate ==> ";
    cin >> *hours >> *payrate;
    cout << "  Enter the deferred earning amount ==> ";
    cin >> *defr;
cout*hours>>*工资率;
cout>*defr;
我不知道
cout
%8.2f
的等价物。我只是被卡住了

TL;DR:%f表示正在打印的浮点值。%8.2f表示字符总数为8(或“%8.2f”中点之前的任何其他数字),点之后为2(或%f命令中点之后的任何其他数字)

在这种情况下,可以打印诸如“12345.78”之类的数字

芜?但是8个数字!不,是角色。该点包含在总计数中


希望这有帮助

这应该有助于Docs+示例:为什么不直接将浮点数冲刺到本地字符缓冲区中,然后将这些缓冲区删除呢?您可以保持相同的printf格式,同时仍对文件IO使用iostream。或者更好的方法是,创建一个函数,将printf转换为它自己的本地缓冲区并返回一个std::string,然后在cout行内联调用该函数。这如何回答如何将
printf()
调用转换为
cout
?这个问题可能有三种含义。第一:OP知道所有的printf选项,但是在找到iostream等价物时遇到了困难。第二:OP知道所有iostream选项,但不了解printf的选项。第三:OP既不知道printf选项,也不知道iostream选项。对于第二种解释,这是一个正确且有用的答案,但仅对于第二种解释,对于其他两种解释都是无用的。我不认为第二种解释是正确的。
{
    cout << " Enter the name ==> ";
    cin >> *firstname >> *lastname;
    cout <<" Enter the hours and payrate ==> ";
    cin >> *hours >> *payrate;
    cout << "  Enter the deferred earning amount ==> ";
    cin >> *defr;