我正在做以下练习:
我的代码:
#include <string>
#include <fstream>
#include <iostream>
#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;
}
但是当我用 MS VS 调试它时..它只是说“按任意键继续...”
我在哪里添加 Data.txt 文件?
最佳答案
好吧,鉴于您没有向屏幕输出任何内容,我一点也不惊讶您看到的就是这些。
如果我是你,我会查看 Output.dat
文件,看它是否正在写入任何内容。
如果您在该文件中看不到任何内容,则可能是因为您在运行的目录中没有 Data.txt
文件。对于 VS,这通常位于解决方案目录内某处的 bin
或 debug
目录下。
您可以通过将 system("cd");
放在代码的开头并运行它来找出是哪个目录。
关于c++ - 我的程序没有从文件 :/输出任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4952785/