以字符为单位设置控制台大小

Set console size in characters

本文关键字:控制台 设置 字符 为单位      更新时间:2023-10-16

到目前为止,我希望无论它在什么设备上运行,都能够将控制台大小设置为

完全相同
static const int nScreenWidth = 80;
static const int nScreenHeight = 30;
int main()
{
system("MODE CON COLS=80 LINES=30");
}

但是由于我将宽度和高度存储在变量中,因此需要手动更改,这并不酷。 我试过了

system("MODE CON COLS=" + std::to_string(nScreenWidth).c_str() + " LINES=30");

但我得到表达式必须具有整数或无作用域枚举类型。

所有功能来自

#include <windows.h>

以像素为单位设置控制台大小,但我需要它以字符为单位。

看看这是否有帮助:

std::string str = "MODE CON COLS=" + std::to_string(nScreenWidth) + " LINES=30";
system(str.c_str());