gpt4 book ai didi

c++ - 非常基本的文件输入/输出

转载 作者:太空宇宙 更新时间:2023-11-03 10:20:51 25 4
gpt4 key购买 nike

每当我尝试使用 istream 打开文件时,它都打不开(is_open() 返回 false)。是否需要将文件放在特定目录中才能访问(它在项目的输出目录中)?

ifstream ifile;
ifile.open("test.txt");
if(!ifile.is_open()){
cout << "The file could not be opened." << endl;
}
cin.get();

最佳答案

它需要在程序的“工作目录”中。这是您运行程序时所在的目录,或者如果您使用的是 Visual Studio 等 IDE,则为项目目录(该目录还包含发布和/或调试构建文件夹)。

关于c++ - 非常基本的文件输入/输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5778941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com