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

PHP Code:
int main()
{
    
// Create Screen Buffer
    
wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];
    
HANDLE hConsole CreateConsoleScreenBuffer(GENERIC_READ GENERIC_WRITE0NULLCONSOLE_TEXTMODE_BUFFERNULL);
    
SetConsoleActiveScreenBuffer(hConsole);
    
DWORD dwBytesWritten 0;

...
    
screen[nScreenWidth nScreenHeight 1] = '\0';
    
SetConsoleTextAttribute(hConsole0xaa);
    
WriteConsoleOutputCharacter(hConsolescreennScreenWidth nScreenHeight, { 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?