我正在开发一个具有一些本机代码(运行时组件)的WP8应用程序。 在运行时组件内部,我需要检查c样式数组的内容。 因为这个数组不小,我认为我能做的最好就是将数组写入文件中 使用fopen / fwrite / fclose; 检查fopen和fwrite的返回值,我可以看到它成功了。 但我找不到该文件(使用Windows Phone Power Tools)。
那么文件在哪里写的? 是否有另一种方法可以将视频工作室中的数组内容转储到文件中(在计算机上)?
答案 0 :(得分:1)
我不熟悉WP8中的fopen / fwrite / fclose API。这可能意味着它不是可用于提交应用程序的白名单API。在C ++中使用IsoStore时,最好只使用“Windows :: Storage :: ApplicationData :: Current-> LocalFolder”。请参阅Win8代码示例@ http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700361.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1
答案 1 :(得分:1)
感谢贾斯汀,
这是我最终如何做到的:
auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;
Concurrency::task<Windows::Storage::StorageFile^> createFileOp(
folder->CreateFileAsync(L"Data.bin", Windows::Storage::CreationCollisionOption::ReplaceExisting));
createFileOp.then(
[nData, pData](Windows::Storage::StorageFile^ file)
{
return file->OpenAsync(Windows::Storage::FileAccessMode::ReadWrite);
})
.then([nData, pData](Windows::Storage::Streams::IRandomAccessStream^ stream)
{
auto buffer = ref new Platform::Array<BYTE>(pData, nData);
auto outputStream = stream->GetOutputStreamAt(0);
auto dataWriter = ref new Windows::Storage::Streams::DataWriter(outputStream);
dataWriter->WriteBytes(buffer);
return dataWriter->StoreAsync();
})
.wait();
现在将其与我的“意思”进行比较:
FILE *fp = fopen("Data.bin", "wb");
if (fp)
{
int ret = fwrite(pData, 1, nData, fp);
fclose(fp);
}