如何在控制台中获得我的进程绑定到的行字符数

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

本文关键字:绑定 字符 进程 我的 控制台      更新时间:2023-10-16

转述我的问题:用字符来表示控制台的宽度。

这个在windows中默认设置为80,但是用户可以改变它,如何获得这个值?

可以使用GetConsoleScreenBufferInfo函数

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