C++ standard output format

十年热恋 提交于 2019-11-28 11:39:47

问题


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"

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?


回答1:


C++ itself does not have this feature, it's I/O model is a fairly simple, sequential one.

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.




回答2:


A library, like ncurses can help you do this.



来源:https://stackoverflow.com/questions/9451293/c-standard-output-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!