简体   繁体   English

如何使用C ++将二进制数据写入Windows应用商店中的文件

[英]How to write Binary data to a file in a windows store app using c++

Hey I'm having trouble with file IO. 嘿,我在处理文件IO时遇到了麻烦。 I am using some standard file pointer stuff but i keep getting this error: Unhandled exception at 0x58CBC465 (msvcr120_app.dll) in ChemicalWar.exe: An invalid parameter was passed to a function that considers invalid parameters fatal. 我正在使用一些标准的文件指针,但是我一直收到此错误:ChemicalWar.exe中0x58CBC465(msvcr120_app.dll)的未处理异常:无效参数传递给认为无效参数致命的函数。

Now from what I gathered I think it has something to do with not having permission to write to default location but I am unsure how to change the location. 现在,从我收集的信息来看,我认为这与无权写入默认位置有关,但是我不确定如何更改位置。

here is the code I wrote so far that is giving me trouble: 这是我到目前为止编写的给我带来麻烦的代码:

FILE* ofile;
NametoBinary(_filename);
fopen_s(&ofile, (char*)folder->ToString(), "wb");
fwrite(&animhead, sizeof(Afhead), 1, ofile);
fwrite(binbuff.data(), sizeof(unsigned char), binbuff.size(), ofile);
fclose(ofile);

it breaks on the first fwrite call. 它在第一个fwrite调用时中断。 Any help would be great. 任何帮助都会很棒。 Thanks in advance. 提前致谢。

So I figured out the solution so I will post it in case anyone else needs to know. 所以我想出了解决方案,以便在其他人需要知道的情况下发布。

FILE* ofile = nullptr;
NametoBinary(_filename);
auto folder = Windows::Storage::ApplicationData::Current->RoamingFolder;
std::wstring ws(folder->Path->Data());
std::string full(ws.begin(), ws.end());
full += "\\";
full += _filename;
fopen_s(&ofile, full.c_str(), "wb");
if (nullptr == ofile) return false;
fwrite(&animhead, sizeof(Afhead), 1, ofile);

So the new windows apps have there own FileI0 system. 因此,新的Windows应用程序具有自己的FileI0系统。 This solution will save a file in a folder in the appdata folder. 此解决方案会将文件保存在appdata文件夹的文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM