C++ 我的程序没有从文件中输出任何内容:/

C++ 我的程序没有从文件中输出任何内容:/,c++,input,ofstream,C++,Input,Ofstream,我正在做以下练习: 我的代码: #include <string> #include <fstream> #include <iostream> #include <iomanip> using namespace std; int main() { ifstream inFile; ofstream outFile; double currentSalary, increaseRate, updatedSalary

我正在做以下练习:

我的代码:

#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;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
河流充填;
出流孔的直径;
双倍当前薪资、加薪率、更新薪资;
字符串firstName,lastName;
infle.open(“Data.txt”);
outFile.open(“Output.dat”);
outFile>firstName;
填充>>当前工资>>增加率;
更新工资=当前工资*(1+增加率/100);
输出文件当前工资>>增加率;
更新工资=当前工资*(1+增加率/100);
输出文件当前工资>>增加率;
更新工资=当前工资*(1+增加率/100);

outFile好吧,既然你没有向屏幕输出任何东西,我一点也不奇怪你看到的就是这些

如果我是你,我会查看
Output.dat
文件,看看它是否在写什么

如果您在该文件中没有看到任何内容,则可能是因为您运行的目录中没有
Data.txt
文件。对于VS,它通常位于解决方案目录中的
bin
debug
目录下


您可以通过将
system(“cd”);
放在代码的开头并运行它来找出它所在的目录。

好吧,既然您没有向屏幕输出任何内容,我一点也不奇怪这就是您所看到的

如果我是你,我会查看
Output.dat
文件,看看它是否在写什么

如果您在该文件中没有看到任何内容,则可能是因为您运行的目录中没有
Data.txt
文件。对于VS,它通常位于解决方案目录中的
bin
debug
目录下


您可以通过将
system(“cd”);
放在代码的开头并运行它来找出哪个目录。

您必须将Data.txt放在将执行二进制文件的同一目录中,或者放置Data.txt的绝对路径,如
infle.open(“C:\Documents\Data.txt”)
,否则将永远找不到。

您必须将Data.txt放在执行二进制文件的同一目录中,或将Data.txt的绝对路径放在同一目录中,如
infle.open(“C:\Documents\Data.txt”)
,否则将永远找不到。

预期的行为是什么?是否写入
输出.dat
?如果不在屏幕上打印,则没有理由使用
暂停
。购买的练习和原地编码可以删除对外部站点的依赖关系。您是否有
数据.txt
文件?您知道当前使用的是什么吗运行程序时,nt目录是什么?您可以执行
system(“CHDIR”)
我相信是看到了。谢谢各位。它解决了我的问题。预期的行为是什么?它是否正在写出
输出.dat
?如果你没有打印到屏幕上,没有理由使用
暂停
。购买了练习和代码,以便消除对外部站点的依赖。你有
data.txt
文件吗?你知道吗当你运行程序时,你知道当前目录是什么吗?我相信你可以做
system(“CHDIR”);
来查看它。谢谢各位。它解决了我的问题。啊,非常感谢。我当时很激动,然后意识到我没有向屏幕输出任何东西。啊,非常感谢。我当时很激动,然后意识到我没有向屏幕输出任何东西。