C++ 标准输出格式 [英] C++ standard output format

查看:35
本文介绍了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++ 标准输出格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆