本文介绍了[UWP] [C ++]使用std :: ifstream读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道UWP应用程序是沙盒的,这就是为什么你无法访问预设位置以外的文件。


然而,在我的应用程序中,我向用户询问FilePicker他们想要访问的文件夹。通常它会像"C:\ DataImages \"一样。哪个工作正常。我将目录添加到我未来的访问列表中,因此当他们再次启动应用程序时,在稍后的
日期,它仍然可以访问以前选择的文件夹。这很好。


用户对图像执行各种操作后,我想将自定义数据文件与图像文件一起保存。我已经有一个C ++类来处理所有这些,我会缩进重用但它不起作用。


它使用以下内容来读取数据......

 

std :: ifstream readFile(Filename,std :: ios :: in);

readFile.is_open(); //总是失败

我可以使用...枚举所有文件。

 

CreateFileQuery();

GetFilesAsync();

从而确认应用程序可以访问我需要的所有文件。我只是无法使用std :: ifstream读取它们。


解决方案

I understand that UWP apps are sandboxed that's why you cannot access files outside of pre-set locations.

However, in my app I ask the user with a FilePicker which folder they want to access. Typically it will be something like "C:\DataImages\" which works fine. I add the directory to my future access list so when they launch the app again, at a later date, it can still access the previously selected folder. This works fine.

After the user performs various actions on the images I want to save a custom data file along with the image file. I already have a C++ class that handles all this that I indent to reuse but it won't work.

It uses the following to read data...

std::ifstream readFile(Filename, std::ios::in);

readFile.is_open(); //always fails

I can enumerate all the files using...

CreateFileQuery();

GetFilesAsync();

thus confirming the app has access to all the files I need. I just cannot read them using std::ifstream.

解决方案


这篇关于[UWP] [C ++]使用std :: ifstream读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:52