【发布时间】:2014-05-31 17:30:56
【问题描述】:
我最近试图获取运行该程序的终端的大小。
问题是脚本+程序方案不方便,不支持用户输入或终端大小变化。
如何在 C++ 代码中做到这一点(不会弄乱脚本)?
我的代码:
Bash 文件(要运行的文件而不是 C++ 程序):
cols=`tput cols`
lines=`tput lines`
input="${cols}\n${lines}"
echo -ne "${input}" | [C++ program]
C++ 文件(实际程序):
#include <iostream>
int main() {
unsigned lines;
unsigned cols;
cin >> cols;
cin >> lines;
// some code here
}
【问题讨论】:
-
使用ncurses
-
system("tput cols")...可以做到我认为的伎俩,但我从未尝试过。 -
你也必须链接到ncurses。
-
编译命令末尾通常是
-lncursesw或-lncurses