c++文件IO,如何指定输出位置

C++ File IO, how to specify output location

本文关键字:何指定 输出 位置 文件 IO c++      更新时间:2023-10-16

我一直在尝试通过教程网站学习c++中的File IO,并遇到了以下代码。

现在,我如何指定输出文件的位置?我已经尝试运行代码并搜索文件的位置,但没有工作。

谢谢。

ofstream myfile ("InOutExample.txt");
if (myfile.is_open())
{
    myfile << "This is a line.n";
    myfile << "This is another line.n";
    myfile.close();
}
else cout << "Unable to open file";
return 0;

system("pause");

如果你指定了位置,它会把它放在那里。

ofstream myfile ("c:\temp\InOutExample.txt");

如果你没有输入完整路径,它会把它放在当前工作目录