// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>

using namespace std;

#include <windows.h>

class Console
{
private:
    HANDLE handle;
    CONSOLE_SCREEN_BUFFER_INFO pcsbInfo;
    void getHandle();
public:
    Console() { handle = NULL; }
    int getBufferHeight();
    int getBufferWidth();
};

int Console::getBufferHeight()
{
    getHandle();
    if (GetConsoleScreenBufferInfo(handle, &pcsbInfo))
    {
        return pcsbInfo.dwSize.Y;
    }
    else
    {
        throw "GetConsoleScreenBufferInfo failed";
    }
}

int Console::getBufferWidth()
{
    getHandle();
    if (GetConsoleScreenBufferInfo(handle, &pcsbInfo))
    {
        return pcsbInfo.dwSize.X;
    }
    else
    {
        throw "GetConsoleScreenBufferInfo failed";
    }
}

void Console::getHandle() {
    if (handle == NULL) {
        handle = GetStdHandle(STD_OUTPUT_HANDLE);
    }
}

int main()
{
    Console *con = new Console();
    cout << con->getBufferWidth() << " x " << con->getBufferHeight() << endl;
    return 0;
}
