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

查看:474
本文介绍了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天全站免登陆