c++ - 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.
解决方案
我想您错过了每个 winrt 应用程序都在自己的沙箱中运行的重要事实。您尝试访问的每个文件路径都是相对于应用程序沙箱根目录的,尽管给定路径是绝对的,但它在沙箱中是绝对的,系统会将其解释为沙箱根目录的相对路径。要访问沙箱外的文件,您应该付出更多努力,声明一个在沙箱之间共享所需文件的路径,或者将文件放入已经可用的系统共享目录中。在这种情况下,路径将不再是绝对路径,它将相对于共享路径进行访问。
推荐阅读
- javascript - 删除所有重复出现的 JSON 对象数组
- javascript - 如何从函数返回一个值,使用该值制作数学公式并将解决方案(键/值)推送到对象数组?
- javascript - 错误:试图在 React 函数组件中打印出数组元素?
- sharepoint - 如何在 SharePoint TeamsPersonalApp 中编辑属性?
- mysql - CASE功能可以改进吗?
- swift - SwiftUI 使用枚举构建列表
- javascript - 道场图中更好的时间刻度和轴标签
- android - Android 10 中的服务器连接问题
- javascript - 如何停止内圈div内的webkit动画?
- artificial-intelligence - 如何检查 PDDL 中的条件?