簡體   English   中英

如何在 C++/WinRT 控制台應用程序中包含系統

[英]How to include System in C++/WinRT console application

使用 Visual Studio 2019 16.10.2 如何在 C++/WinRT 控制台程序中包含 .NET 組件?

IVector indexOf方法需要來自System UInt32結構

在這種情況下如何使用System 嘗試使用命名空間會導致

"System' : a namespace with this name does not exist"

這已經在 SO 上進行了介紹,但僅適用於 C++/CLI 應用程序,而不是 C++/WinRT 控制台應用程序的上下文。 該帖子中提供的解決方案也不起作用。

#include "pch.h"

#include <Windows.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>

using winrt::Windows::Foundation::Collections::IVector;
using namespace System;

int main()
{
    IVector<int> foo;
    foo.Append(1);
    UInt32 bar;
    foo.indexOf(1, bar);

    return EXIT_SUCCESS;
}

在這種情況下pch.h是空的。

當您從右上角 (C++/WinRT) 文檔的語言下拉列表中選擇適當的語言時,您將看到 C++/WinRT 特定的簽名:

bool IndexOf(T const& value, uint32_t & index);

你需要更換

UInt32 bar;

uint32_t bar{};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM