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



我想创建一个 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:

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++ 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.

登录 关闭
发送“验证码”获取 | 15天全站免登陆