If the project is a GUI project, no console will appear. In order to change the project into a console one you need to go to the project properties panel and set:
- In "linker->System->SubSystem" the value "Console (/SUBSYSTEM:CONSOLE)"
- In "C/C++->Preprocessor->Preprocessor Definitions" add the "_CONSOLE" define
This solution works only if you had the classic "int main()" entry point.
But if you are like in my case (an openGL project), you don't need to edit the properties, as this works better:
AllocConsole();
freopen("CONIN$", "r",stdin);
freopen("CONOUT$", "w",stdout);
freopen("CONOUT$", "w",stderr);
printf and cout will work as usual.
If you call AllocConsole before the creation of a window, the console will appear behind the window, if you call it after, it will appear ahead.
Update
freopen
is deprecated and may be unsafe. Use freopen_s
instead:
FILE* fp;
AllocConsole();
freopen_s(&fp, "CONIN$", "r", stdin);
freopen_s(&fp, "CONOUT$", "w", stdout);
freopen_s(&fp, "CONOUT$", "w", stderr);