【发布时间】:2015-10-03 18:06:51
【问题描述】:
我正在用 c++ 编写一个 Windows 应用程序(非 xaml)并尝试使用以下命令读取我的项目目录中的文件:
FILE* mFile = fopen(filename, "rb");
我也试过了:
errno_t err = fopen_s(&mFile, filename, "rb");
在这种情况下,errno 为 2,在这两种情况下 mFile 之后都为 null。
我很难找到解释如何简单地打开和读取文件的 c++ 代码。 文件名是这样的:“./aDirectory/anotherDirectory/thefile”
我的解决方案目录看起来像省略了很多东西:
- AppName.Shared
- AppName.Windows
aDirectory- anotherDirectory
- 文件
- AppName.WindowsPhone
我在 API 中看到了一个称为 FilePicker 的东西,但它看起来有点过分,而且与 UI 的关系比我需要的要多。
将文件包含到我的项目中然后在 Windows 运行时加载它们的适当方法是什么?
【问题讨论】:
-
2 表示找不到路径。检查您的程序认为工作目录在哪里 [GetCurrentDirectory ](msdn.microsoft.com/en-us/library/windows/desktop/….
-
@user4581301 该链接无效,根据该链接msdn.microsoft.com/en-us/library/windows/apps/hh464945.aspx ,windows store 应用无法使用GetCurrentDirectory
-
用 ] 代替了 ) 链接。对于那个很抱歉。重点是没有意义的。你能写一个文件看看它在哪里结束吗?
-
@user4581301 不幸的是,我也无法写入文件来工作。没有运气
-
那么,只有我一个人认为这是 C 代码吗?为什么不使用标准的 std::ifstream?
标签: c++ fopen c++-cx win-universal-app