class outbuf : public std::streambuf {
public:
outbuf() {
setp(0, 0);
}
virtual int_type overflow(int_type c = traits_type::eof()) {
return fputc(c, stdout) == EOF ? traits_type::eof() : c;
}
};
class woutbuf : public std::wstreambuf {
public:
woutbuf() {
setp(0, 0);
}
virtual int_type overflow(int_type c = traits_type::eof()) {
return fputwc(c, stdout) == EOF ? traits_type::eof() : c;
}
};
void CreateConsole() {
AllocConsole();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
//Фиксим std вывод.
FILE* fpstdin = stdin, * fpstdout = stdout, * fpstderr = stderr;
freopen_s(&fpstdin, "CONIN$", "r", stdin);
freopen_s(&fpstdout, "CONOUT$", "w", stdout);
freopen_s(&fpstderr, "CONOUT$", "w", stderr);
//Фиксим std::cout, std::wcout.
outbuf ob; woutbuf wob;
std::cout.rdbuf(&ob);
std::wcout.rdbuf(&wob);
//Если вдруг окно скрыто, показываем его.
ShowWindow(GetConsoleWindow(), SW_SHOW);
}