Hi everyone, the code below is my setup for opening a console in a Win32 project (using visual studio) and having the cout print stuff on it, it is mostly copy-pasted from stackoverflow with some trial and error changes I did without being sure of what I was doing, but it works. Though now I want to understand it, code below
void debugConsole(bool create = true);
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine, int show)
{
#if defined(DEBUG) || defined(_DEBUG)
debugConsole();
#endif
return 0;
}
void debugConsole(bool create)
{
if (create)
{
//Create Console
FILE* stream;
AllocConsole();
freopen_s(&stream, "conout$", "w", stdout);
}
}
So from what I can tell, I am telling it that now the stdout stream (stuff I send using std::cout) get written (that's why the "w") to the console output, which is specified using "conout$".
So basically freopen_s job is to send a stream somewhere else?
But where is the "conout$" coming from? There is like a switch inside freopen_s that tells it the meaning of "conout$", which would be "send stuff to console"?
What is the FILE* stream sent to freopen_s doing though?
also let's say that under that line I write
freopen_s(&stream, "output.txt", "w", stdout);
I tried this out and it creates said file and put the cout output into it, which is great, but what if I want both? How do I set it up in a way than now cout content is cloned and sent both to the console and to my output file?
Thanks
↧