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

不打扰是莪最后的温柔 提交于 2019-12-09 02:02:05

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/8627327/how-to-get-number-of-characters-in-line-in-console-that-my-process-is-bind-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!