c++ - 将 stdio.h 程序转换为 iostream

标签 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
    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;

使用 stdio.h 输入 putemployeedata.cpp

//3.3
#include <stdio.h>
#define ADDR(var) &var

void InputEmployeeData(char *lastname,char *firstname, // 3.3
                       float *hours,float *payrate, float *defr);

void InputEmployeeData(char *lastname,char *firstname, // 3.3
                       float *hours,float *payrate, float *defr)
{
    printf(" Enter the name ==> ");
    scanf("%s%s",firstname,lastname);
    printf(" Enter the hours and payrate ==> ");
    scanf("%f%f",hours,payrate);
    printf("  Enter the deferred earning amount ==> ");
    scanf("%f",defr);
}

使用 iostream 的 inputemployeedata.cpp

{
    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%8.2f 等价物。我只是卡住了 enter image description here

最佳答案

C: printf a float value

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

在这种情况下,可能会打印一个数字,例如“12345.78”。

呃?但是8个数字!不,人物。该点包含在总数中。

希望这对您有所帮助!

关于c++ - 将 stdio.h 程序转换为 iostream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33089272/

相关文章:

c++ - 减少将参数传递给函数所需的字符串流操作的冗长程度

c++ - C++中使用静态非成员函数的原因和意义是什么?

php - Predis 上 BLPOP 的正确语法是什么?

perl - 在Perl中,创建与程序包同名的子例程是否有害?

c - 在 C 中通过指针为结构中的变量赋值

haskell - 正斜杠在haskell中意味着什么?

c++ - Qt QextSerialPort 静态库

c++ - 第一次发送后未立即生成 SIGPIPE

c++ - C 和 C++ 差异行为

c - xcode 和 bash 中 opencl 的某些意外行为?