简体   繁体   English

C ++标准输出格式

[英]C++ standard output format

I want to create a C++ console application that print some text to different parts of the console. 我想创建一个C ++控制台应用程序,该应用程序将一些文本打印到控制台的不同部分。 For example in QBasic you can use: 例如,在QBasic中,您可以使用:

locate(8,5)
print "hi"

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. 嗨将在第8列第5行中打印。在C ++中,当我使用cout时,它将始终在下一行中打印,并在第一列中开始打印。 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. C ++ 本身不具有此功能,它的I / O模型是一个相当简单的顺序模型。

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. 如果要进行精美的光标定位,则需要输出(例如) 终端将识别为特殊命令的控制字符(例如ANSI或VT转义序列),或使用类似curses的库(请参见ncurses )。它可以为您完成很多繁重的工作,不仅是光标定位,还包括文本模式窗口等。

ncurses这样的库可以帮助您做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM