C++ standard output format(C++ 标准输出格式)
问题描述
我想创建一个 C++ 控制台应用程序,将一些文本打印到控制台的不同部分.例如在 QBasic 中,您可以使用:
I want to create a C++ console application that print some text to different parts of the console. For example in QBasic you can use:
locate(8,5)
print "hi"
hi 将在第 8 列第 5 行打印.在 C++ 中,当我使用 cout 时,它总是在下一行打印,并在第一列开始打印.有什么办法可以做到吗?
And hi would be printed in column 8 line 5. In C++ when I use cout it always prints on the next line, and begins printing in the first column. Is there any way I can do this?
推荐答案
C++本身没有这个特性,它的I/O模型是相当简单的,顺序的.
C++ itself does not have this feature, it's I/O model is a fairly simple, sequential one.
如果您想进行花哨的光标定位,您需要输出(例如)您的 终端 将识别为特殊命令(例如 ANSI 或 VT 转义序列)的控制字符,或者使用像 curses 这样的库(参见 ncurses 这里),它可以做很多事情grunt 为你工作,不仅仅是光标定位,还有文本模式窗口等.
If you want to do fancy cursor positioning, you'll need to output (for example) control characters which your terminal will recognise as special commands (such as ANSI or VT escape sequences), or use a library like curses (see ncurses here) which can do a lot of the grunt work for you, not just cursor positioning but also things like text mode windows and so forth.
这篇关于C++ 标准输出格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 标准输出格式
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
