【发布时间】:2014-12-17 15:25:12
【问题描述】:
我想使用 C++ 创建文件,然后我可以将其导出以供其他地方使用。下面的代码似乎可以创建文件,因为我可以将数据写入文件,然后稍后在 C++ 程序中再次读取它。但是,当我尝试实际找到创建的文件以便使用它时,却无处可寻..
using namespace std;
int main () {
ofstream myfile ("example3.dat");
if (myfile.is_open()){
myfile << 3335 << " " << 64 << " " << 43 << 9 << 5 << 6 << 5 << 4 << 6;
myfile.close();
}
else cout << "Unable to open file";
ifstream myfile2 ("example3.dat");
int b;
myfile2 >> b; cout <<b;
myfile2 >> b; cout <<b;
myfile2.close();
return 0;
}
【问题讨论】:
-
cd /find . -name example3.dat -print -
@sleeping_dragon:当前目录并不总是exe的目录。
-
可以在Debug文件夹中吗?
-
这个问题似乎是题外话,因为它是关于在您的计算机硬盘驱动器上查找文件。
-
澄清@sleeping_dragon 的评论 - 文件将位于您运行程序的目录中,因为该程序仅使用文件名,并且从不更改目录。如果您将其运行为例如,这很可能与程序本身的位置不同。
/path/to/my/program...
标签: c++