如何在 Windows Phone 8 上使用 C++ 创建文件? [英] How to create file using C++ on windows phone 8?

查看:24
本文介绍了如何在 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.

这篇关于如何在 Windows Phone 8 上使用 C++ 创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆