1

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

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

4

1 回答 1

1

只需替换这一行:

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

用这条线:

concurrency::task<StorageFile^> fileOperation(localFolder->CreateFileAsync("data.txt",
    CreationCollisionOption::ReplaceExisting));
于 2012-12-16T03:11:53.477 回答