m0nde
01-27-2019, 11:53 PM
i'm learning c++ and want to know if there is a way to target all systems in one method when i want to write directly to the console
i wrote a windows program where I'm using
int main()
{
// Create Screen Buffer
wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];
HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
SetConsoleActiveScreenBuffer(hConsole);
DWORD dwBytesWritten = 0;
...
screen[nScreenWidth * nScreenHeight - 1] = '\0';
SetConsoleTextAttribute(hConsole, 0xaa);
WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, { 0,0 }, &dwBytesWritten);
}
it works fine. i have 2 questions, what do i do to do that in a way which will work on any system? is that even possible?
i wrote a windows program where I'm using
int main()
{
// Create Screen Buffer
wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];
HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
SetConsoleActiveScreenBuffer(hConsole);
DWORD dwBytesWritten = 0;
...
screen[nScreenWidth * nScreenHeight - 1] = '\0';
SetConsoleTextAttribute(hConsole, 0xaa);
WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, { 0,0 }, &dwBytesWritten);
}
it works fine. i have 2 questions, what do i do to do that in a way which will work on any system? is that even possible?