有谁知道我做错了什么。
// STORAGE FILE
StorageFile^ saveFile;
// FILE PICKER, FOR SELECTING A SAVE FILE
FileOpenPicker^ filePicker = ref new FileOpenPicker;
// ARRAY OF FILE TYPES
Array<String^>^ fileTypes = ref new Array<String^>(1);
fileTypes->Data[0] = ".txt";
filePicker->ViewMode = PickerViewMode::Thumbnail;
filePicker->SuggestedStartLocation = PickerLocationId::Desktop;
filePicker->FileTypeFilter->ReplaceAll(fileTypes);
// THIS SHOULD HOPEFULLY LET US PICK A FILE
saveFile = filePicker->PickSingleFileAsync();
特别是最后一行:
saveFile = filePicker->PickSingleFileAsync();
我收到以下错误。
错误C2440:&#39; =&#39;:无法转换为&#39; Windows :: Foundation :: IAsyncOperation ^&#39;到&#39; Windows :: Storage :: StorageFile ^&#39;
答案 0 :(得分:1)
错误C2440:&#39; =&#39;:无法转换为&#39; Windows :: Foundation :: IAsyncOperation ^&#39;到&#39; Windows :: Storage :: StorageFile ^&#39;
PickSingleFileAsync
是异步方法,返回类型为Windows::Foundation::IAsyncOperation
,无法转换为StorageFile
类型。正如Hans Passant所说,你可以使用create_task()
来等待这种异步操作。
create_task(folderPicker->PickSingleFolderAsync()).then([this](StorageFolder^ folder)
{
if (folder)
{
//do some stuff
}
else
{
//do some stuff
}
});
有关详情,请参阅Asynchronous programming in C++。