1

Rephrasing my question: width of a console in term of characters.

This in windows is set by default to 80 but user can change it, how to get this value ?

rsk82
  • 28,217
  • 50
  • 150
  • 240

1 Answers1

3

You can use the GetConsoleScreenBufferInfo function.

CONSOLE_SCREEN_BUFFER_INFO csbi;
if(!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
{
    // an error occourred
    cerr<<"Cannot determine console size."<<endl;
}
else
{
    cout<<"The console is "<<csbi.srWindow.Right-csbi.srWindow.Left<<" wide."<<endl;
}
Matteo Italia
  • 123,740
  • 17
  • 206
  • 299