rsk82
rsk82

Reputation: 29387

how to get number of characters in line in console that my process is bind to?

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 ?

Upvotes: 1

Views: 5879

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126827

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;
}

Upvotes: 3

Related Questions