C ++ File IO,如何指定输出位置

时间:2013-03-20 15:29:44

标签: c++ file-io

我一直在尝试通过教程网络学习C ++中的文件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");

1 个答案:

答案 0 :(得分:1)

如果您指定位置,则会将其放在那里。

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

如果您没有填写完整路径,则将其放在当前工作目录中。