开发者

My program is not outputting anything from the file :/

开发者 https://www.devze.com 2023-02-09 20:47 出处:网络
I am doing the following exercise: My code: #include <string> #include <fstream> #include <iostr开发者_如何学编程eam>

I am doing the following exercise:

My program is not outputting anything from the file :/

My code:

#include <string>
#include <fstream>
#include <iostr开发者_如何学编程eam>
#include <iomanip>

using namespace std;

int main()
{
    ifstream inFile;
    ofstream outFile;

    double currentSalary, increaseRate, updatedSalary;
    string firstName, lastName;

    inFile.open ("Data.txt");
    outFile.open("Output.dat");
    outFile << fixed << showpoint << setprecision(2);
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);
    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);

    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);
    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;

    system("PAUSE");
    return 0;
}

But when I debug it with MS VS.. it just says "press any key to continue..."

Where do I add the Data.txt file?


Well, given that you don't output anything to the screen, I'm not at all surprised that's all you see.

If I were you, I'd have a look at the Output.dat file to see if it's writing anything.

If you're seeing nothing in that file, then it's probably because you don't have your Data.txt file in the directory where you're running. With VS, this is usually under the bin or debug directory somewhere inside your solution directory.

You can find out which directory that is by putting system("cd"); at the start of your code and running it.


You have to put the Data.txt at the same directory where you will execute the binary file or put the absolute path of Data.txt, like inFile.open ("C:\Documents\Data.txt"), otherwise will never be found.

0

精彩评论

暂无评论...
验证码 换一张
取 消