首页 > 解决方案 > winrt trouble with std::filesystem?

问题描述

I cloned https://github.com/kennykerr/cppwinrt, and added the two lines @line 70 (after including the filesystem header):

if (!std::experimental::filesystem::exists(winrt::to_string(file.Path())))
    exit(12345);

And it exits with 12345. Always. Why? I thought winrt was supposed to work with standard iso c++? Even if I hardcode a filename instead of the "to_string(data_file)", it still dies.

If it has something to do with UWP running in a sandbox, that's fine, but why isn't the filepicker working?

This is more or less the easiest example I can pull up. For some reason, no matter what I try, I cannot operate on files.

标签: c++uwpwindows-runtime

解决方案


我想您错过了每个 winrt 应用程序都在自己的沙箱中运行的重要事实。您尝试访问的每个文件路径都是相对于应用程序沙箱根目录的,尽管给定路径是绝对的,但它在沙箱中是绝对的,系统会将其解释为沙箱根目录的相对路径。要访问沙箱外的文件,您应该付出更多努力,声明一个在沙箱之间共享所需文件的路径,或者将文件放入已经可用的系统共享目录中。在这种情况下,路径将不再是绝对路径,它将相对于共享路径进行访问。


推荐阅读