C++程序 infile 无法在 xcode 中打开?

发布于 2024-09-05 20:46:31 字数 577 浏览 2 评论 0原文

替代文本 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南笙 2024-09-12 20:46:31
  1. 在 Xcode 中,展开“Targets”节点并找到您的目标。鉴于我所看到的,它将是那里唯一的一个。
  2. 接下来,右键单击您的项目并添加新的“复制文件”构建阶段。出现对话框时,请确保将目标设置为“产品目录”。
  3. 新的构建阶段将以您指定的任何名称出现在您的目标下方。将您的 in_file 和 out_file 拖到那里。
  4. 编译并运行。
  1. In Xcode, expand the "Targets" node and find your target. Given what I've seen, it'll be the only one there.
  2. Next, right-click on your project and add a new "Copy Files" build phase. When the dialog box comes up, make sure you set the Destination to "Products Directory".
  3. The new build phase will appear beneath your target with whatever name you gave it. Drag your in_file and out_file there.
  4. Compile and run.
难以启齿的温柔 2024-09-12 20:46:31

在您当前的情况下,即使 out_file 不存在,也会创建它(因为您正在使用 std::ofstream)。

另一方面,in_file 必须存在,并且(我猜在创建二进制文件的目录中没有这样的文件),因此会产生错误。

您是否尝试使用二进制文件所在文件夹中的文件启动已编译的应用程序?

In your current case out_file would be created even if it doesn't exist (because you're using std::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?

陪你到最终 2024-09-12 20:46:31

可能程序的工作目录中没有名为“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 the out_file the program creates when it is run, it will be created in the working directory, the same directory where it searches for in_file. And it is not the directory you posted the listing of, the out_file there is too old.)

往日 2024-09-12 20:46:31

结果你必须在这里专门创建文件:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文