How to make the gotoxy function??

Hi everybody. I am trying to program ascii games in the console, such as the snake, or the tron, and I need to use the function gotoxy to set the cursor position in the console in order to refresh the map of the game. The problem is that everything that I find in the internet is made for programing in windows, and I do in linux, ubuntu. In addition, in the few sites where they explain it for linux, they do it for c, and I would like to do it exclusively for c++. This means I dont want to use libraries such as conio.h, stdio.h, as well as functions like printf. I want to do it with cout. Is it posible?
Could anybody please tell me how to make my own gotoxy function for c++ in linux? It should work exactly like the one made for windows.

I don't really know why do everybody choose to make their own function? Why isn't this function included in any standard library of c++? I think it is a very useful and common function, so it should have it public library...

Thanks for answering!!
I do recommend that you do look at ncurses first: http://en.wikipedia.org/wiki/Ncurses
Curses would be the best solution for a full on, text-based app. But you might be able to achieve what you want using ANSI escape codes:
http://en.wikipedia.org/wiki/ANSI_escape_code

See discussion here (the functions shown in the post could be easily converted into manipulators if you so chose.)

ANSI Fun
http://www.cplusplus.com/forum/lounge/78225/#msg421381

I don't have a living version of Ubuntu to check that the code works ok (my installation is currently suffering driver problems after an upgrade...) Even if it "works" it might be too filckery?

Andy
Last edited on
Topic archived. No new replies allowed.