【问题标题】:what is wrong with my file writing in c++/cx for metro app?我用 c++/cx 为 Metro 应用程序编写的文件有什么问题?
【发布时间】:2023-03-22 16:13:02
【问题描述】:

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

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^) {
    }
});

感谢“Sometimes A Developer”修复了错误

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

【问题讨论】:

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


    【解决方案1】:

    只需替换这一行:

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

    用这一行:

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

    【讨论】:

    • 谢谢...消除了错误...但它不会创建文件..还是谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2015-04-28
    • 2012-07-21
    • 2013-09-12
    • 2013-01-04
    • 2017-11-27
    • 1970-01-01
    相关资源
    最近更新 更多