C++程序 infile 无法在 xcode 中打开?
替代文本 http://img638.imageshack.us/img638/5731/screenshot20100613at121.png< /a>
为什么 C++ 程序会产生所示的错误?我特别困惑,因为 outfile 打开时没有错误,但 infile 显示错误?两者在 xcode 中的定义完全相同!我更改了“路径类型”设置但没有成功。打开 infile 总是失败!任何建议将非常感激!
对于那些回复的人,谢谢,但正如您所看到的,但 infile 和 outfile 存在并且位于同一位置:
替代文本http://img709.imageshack.us/img709/9316/screenshot20100613at123.png
alt text http://img638.imageshack.us/img638/5731/screenshot20100613at121.png
Why does the c++ program produce the error shown? I'm especially confused since outfile opens without error yet infile displays the error? Both are defined in xcode exactly the same!! I've altering the "path type" setting without success. The open on infile always fails! Any suggestions would be very much appreciated!!
For those who responded thanks but as you can see but infile and outfile exist and are in the same location:
alt text http://img709.imageshack.us/img709/9316/screenshot20100613at123.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您当前的情况下,即使
out_file
不存在,也会创建它(因为您正在使用std::ofstream
)。另一方面,
in_file
必须存在,并且(我猜在创建二进制文件的目录中没有这样的文件),因此会产生错误。您是否尝试使用二进制文件所在文件夹中的文件启动已编译的应用程序?
In your current case
out_file
would be created even if it doesn't exist (because you're usingstd::ofstream
).in_file
, on the other hand, has to exist, and (I guess there is no such file in the directory with created binary), hence an error is produced.Did you try launching your compiled application with the file in the same folder where the binary file is?
可能程序的工作目录中没有名为“in_file”的文件,因此无法打开该文件进行读取。
对于
outfile
来说这并不重要,因为它是为了写入而打开的,如果它还不存在,它就会被创建。您发布的目录列表没有显示已编译的可执行文件的位置,但可能位于
build
目录中的某个位置。也许这也是它的工作目录和输入文件需要所在的位置。 (查找程序运行时创建的out_file
,它将在工作目录中创建,与搜索in_file
的目录相同。而且它不是您发布列表的目录,其中的out_file
太旧了。)Probably there is no file named "in_file" in the program's working directory, so it can't be opened for reading.
For
outfile
this doesn't matter since it is opened for writing and if it doesn't exist yet it will just be created.The directory listing you posted doesn't show where the compiled executable is, but probably it will be somewhere in the
build
directory. Probably this is then also its working directory and the place where the input file would need to be. (Look for theout_file
the program creates when it is run, it will be created in the working directory, the same directory where it searches forin_file
. And it is not the directory you posted the listing of, theout_file
there is too old.)结果你必须在这里专门创建文件:
Project Path/build/Debug
显然你不能直接在 xcode 项目中定义它
Turns out you have to specifically create the file here:
Project Path/build/Debug
apparently you can't just define it directly in the xcode project