0

Sorry if I'm being dense, but I can't find the console for Visual Studio. I'm in the subsystem:windows mode because I'm writing an app that requires me to be in this mode. Is there a different method of debugging that doesnt use the console? I have some print statements in my C++ program but I can't find where they are printed, can anyone help me find it?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • 1
    Fun-fact: Visual Studio doesn't have one. Instead when you run your project you'll get a separate new conhost window. If you close it, then you will have lost any generated stdout/stderr. – Dai Sep 23 '22 at 12:43
  • https://stackoverflow.com/questions/454681/how-to-keep-the-console-window-open-in-visual-c – Dai Sep 23 '22 at 12:44
  • https://learn.microsoft.com/en-us/cpp/build/vscpp-step-2-build?view=msvc-170 – Dai Sep 23 '22 at 12:44
  • No I am talking about visual studio. I'm in the subsystem:windows mode because I'm writing an app that requires me to be in this mode. Is there a different method of debugging that doesnt use the console? – Elliot Scher Sep 23 '22 at 13:59
  • 1
    if you use `subsystem:windows` then obviously you won't get a console unless you create and attach to one – phuclv Sep 23 '22 at 14:00
  • My old answer shows several ways to create a console: [https://stackoverflow.com/questions/13840942/visual-studio-2012-c-standard-output/13841522#13841522](https://stackoverflow.com/questions/13840942/visual-studio-2012-c-standard-output/13841522#13841522) – drescherjm Sep 23 '22 at 14:21
  • BTW, you can create a GUI application that has subsystem:console. I do that all the time for my debug builds for Qt applications. – drescherjm Sep 23 '22 at 14:27
  • @drescherjm when I switch to subsystem:windows, I get this error: ```LNK2019 unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)``` – Elliot Scher Sep 23 '22 at 14:34
  • The middle section of my linked answer explains how to get around this error. ***To fix this I had to add the following to the Entry Point setting of the Advanced Linker settings: "wWinMainCRTStartup"*** – drescherjm Sep 23 '22 at 14:36
  • @drescherjm, are the quotes part of the statement? – Elliot Scher Sep 23 '22 at 15:23
  • I don't think so. Related: [https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=msvc-170](https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=msvc-170) it would be WinMainCRTStartup if you are not using UNICODE – drescherjm Sep 23 '22 at 15:27
  • You can use `OutputDebugString` as MSalters answered or MessageBox to print something. But I'm curious that why you want to use console in a Windows app. – Minxin Yu - MSFT Sep 26 '22 at 08:20

2 Answers2

0

You can either use an external terminal, ex. xterm, but I think this guide will help you to open and use an integrated terminal in Vscode:

https://code.visualstudio.com/docs/terminal/basics

cs1349459
  • 911
  • 9
  • 27
0

Your print statements are currently just lost - you have chosen not to have a console, since you're in a Windows susbsystem.

There's OutputDebugString, which does write to the Visual Studio "Output" tab. But it won't format the output for you. You can do some std::streambuf magic to make std::cout forward to OutputDebugString, so you get std::ostream formatting.

MSalters
  • 173,980
  • 10
  • 155
  • 350