How to print in a Windows Universal C++ project
Asked Answered
T

2

10

I feel so dumb asking this question but honestly I can't understand why System namespace can't be used! What am I doing wrong? Is there any other way to print a single line in the output? (I am using Visual Studio 2015)

Togs answered 13/10, 2015 at 12:47 Comment(0)
Q
14

I can't understand why System namespace can't be used

Windows Universal app is totally different with traditional desktop app, please check Windows Runtime APIs and Win32 and COM API which lists all Win32 and COM APIs supported for use in UWP apps.

Is there any other way to print a single line in the output? (I am using Visual Studio 2015)

If you need to print message to Output window, use OutputDebugString function in UWP C++/CX project, adding #include to access it, for example:

void CPPUWPApp1::MainPage::LogMessage(Object^ parameter)
{
    auto paraString = parameter->ToString();
    auto formattedText = std::wstring(paraString->Data()).append(L"\r\n");
    OutputDebugString(formattedText.c_str());
}

Usage:

LogMessage("Hello World!");
Qatar answered 13/10, 2015 at 17:13 Comment(0)
H
2

You could do this directly:

OutputDebugString(L"Hello World");

Notice the L in front of the string, to convert it directly to LPCWSTR.

Heavyladen answered 28/4, 2020 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.