To do this programmatically, you can PInvoke the appropriate Win32 console functions (e.g. AllocConsole
to create your own or AttachConsole
to use another process's) from within your own code. This way you have the best control over what actually happens.
If you are OK with having a console window open alongside your other UI for the full lifetime of your process, you can simply change the project properties from within Visual Studio and choose "Console Application", simple as that:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…