我在c ++ / cx中为metro应用程序编写文件有什么问题?

时间:2012-12-16 03:05:23

标签: microsoft-metro local-storage c++-cx

我使用以下代码尝试写入文件:

StorageFolder ^localFolder = ApplicationData::Current->LocalFolder;
concurrency::task<StorageFile^> fileOperation = localFolder->CreateFileAsync("data.txt", CreationCollisionOption::ReplaceExisting);
fileOperation.then([this](StorageFile^ sampleFile)
{
    ::Globalization::DateTimeFormatting::DateTimeFormatter("longtime");
    Platform::String ^str; // other str stuff here

    return FileIO::WriteTextAsync(sampleFile, str);
}).then([this](concurrency::task<void> previousOperation) {
    try {
        previousOperation.get();
    } catch (Platform::Exception^) {
    }
});

通过“有时开发人员”

修复了错误

我从这里得到了代码: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700361.aspx

1 个答案:

答案 0 :(得分:1)

只需替换此行:

concurrency::task<StorageFile^> fileOperation = localFolder->CreateFileAsync("data.txt",
    CreationCollisionOption::ReplaceExisting);

这一行:

concurrency::task<StorageFile^> fileOperation(localFolder->CreateFileAsync("data.txt",
    CreationCollisionOption::ReplaceExisting));