如何在 Windows Phone 8 上使用 C++ 创建文件?
我想在 windows phone 上使用 C++ 创建一个文件,但我不熟悉 Win32 API,你能提供一些代码片段如何使用它们吗?顺便说一句,这里我也想知道在windows phone平台上用c++创建本地文件的速度是否比c#快?谢谢!
I want to create a file using C++ on windows phone, but I'm not familar with Win32 API, could you give some code snippets how to use them? By the way, here also I want to know that whether the spead of creating a local file with c++ is faster than c# on windows phone platform? Thanks!
C++ 的主要挑战是找到可以写入的根目录.
The main challenge in C++ is finding the root directory that you can write into.
您不需要使用 C++ 中的 Win32 协议(这也可能是最不可移植的选项).您还可以使用标准 C FILE* API、标准 C++ 流 API 或新的 WinRT 异步文件 API.
You don't need to use the Win32 protocol from C++ (and that probably the least portable option too). You also could use standard C FILE* APIs, standard C++ stream APIs or the new WinRT async file APIs.
例如使用 FILE*(来自 https://stackoverflow.com/a/15988970/694641).
For example using FILE* (from https://stackoverflow.com/a/15988970/694641).
void SaveToFile()
{
// get local folder (= isolated storage)
auto local = Windows::Storage::ApplicationData::Current->LocalFolder;
auto localFileNamePlatformString = local->Path + "\\game.sav";
FILE* pFile;
auto f = _wfopen_s(&pFile, localFileNamePlatformString->Data(), L"w");
auto res1 = fprintf(pFile, "123456789");
auto res2 = fclose(pFile);
}
除非您尝试修复已知的性能问题,否则我不会担心文件的速度.
I wouldn't worry about the speed of the file unless you're trying to fix a known performance problem.