1

It seems all the "Multiple Consoles in C++" questions on this site are either 7 years old and no longer work, or are in C instead of C++. I've searched the web for any APIs for something of that nature. Is there a way specifically to create multiple consoles in C++?

2
  • 2
    The Windows API doesn't change much. In all likeliness, if you find an article that was published a decade or two ago, it's probably still accurate. Besides, the Windows API is exposed purely as a C interface. Using C++ doesn't buy you anything in terms of features. Commented Aug 29, 2020 at 22:34
  • You can't have more than one console attached to a process, but a single console can have multiple console buffers (which can be swapped). If you want more than one console, you will need to create an additional process for each console. See CreateProcess on how to do that. Commented Jan 28, 2024 at 19:55

1 Answer 1

2

The documentation here: https://learn.microsoft.com/en-us/windows/console/attachconsole says no you can't do that within a single process.

A process can be attached to at most one console. If the calling process is already attached to a console, the error code returned is ERROR_ACCESS_DENIED (5).

This also repeats the theme: https://learn.microsoft.com/en-us/windows/console/allocconsole

A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console. A process can use the FreeConsole function to detach itself from its current console, then it can call AllocConsole to create a new console or AttachConsole to attach to another console.

As Remy Lebeau mentioned in a comment, you can however spawn additional child processes each having their own console windows. See the CREATE_NEW_CONSOLE flag of CreateProcess here: https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags

Sign up to request clarification or add additional context in comments.

3 Comments

So I can create multiple windows in GLFW but I can't create multiple consoles....... Makes sense..
You can, however, spawn new processes that are associated with their own console windows. See the CREATE_NEW_CONSOLE flag of CreateProcess().
The term console dates back to 1959 and represents a line-oriented, text-mode user interface. Traditionally text-mode applications had access to at most one console, but multiple applications can share a console. Windows, Linux, macOS and other OSes all follow this convention. For a multi-window experience there is GUI interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.