Decide whether to run the command line or the GUI based on the input parameters
Before run commandline,i call this function
#ifdef _WIN32
# include <windows.h>
# include <fcntl.h>
# include <io.h>
#endif
void attachConsole()
{
#ifdef _WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
freopen_s(&fDummy, "CONIN$", "r", stdin);
std::ios::sync_with_stdio();
}
#endif
}
But console output is flowing:
exit immediately after the program executes the command-line logic without any extra blank lines or repetitive output. but it go wrong!