首页 > 解决方案 > 如何将我编写的程序应用到我编写的文件(C++)中的不同输入?

问题描述

我希望我的 C++ 程序读取我在 .txt 文件中编写的所有输入,并向我显示我想要的每个输入的输出。我基本上希望程序在我的每个输入上运行,相反,它只读取我的第一个输入。我希望它为我提供的每组信息循环。这是我到目前为止所拥有的:

#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
int main()
{
    ifstream fin;
    ofstream fout;
    fin.open("emp.txt");
    fout.open("output.dat");
    string last, first;
    double salary, increase, nsalary;
    while (fin>>last>>first>>salary>>increase);
    {
    nsalary= salary + ((salary/100.0)*increase);
    fout<<first<<"\t"<<last<<"\t"<<fixed<<showpoint<<setprecision(3)<<salary<<"\t\t"<<nsalary;
    cout<<first<<"\t"<<last<<"\t"<<fixed<<showpoint<<setprecision(3)<<salary<<"\t\t"<<nsalary;
    fin.close();
    fout.close();
}
}

谢谢

标签: c++fileinputfstream

解决方案


推荐阅读