• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1142
  • Last Modified:

gotoxy for cout ?

Is there any way to use gotoxy or clearscreen as I did in pascal for c++ std::cout ?

I want to code a console programm with a user interface for unix and windows.

I'm looking for a way that is platform independent and has no need of additional libraries etc. like nc-curses or so....

  • 4
  • 4
  • 3
  • +4
1 Solution
I don't think this is possible.

The best you can do is try using POSIX, but oddly enough, VC++ does not support most of the POSIX functions.
bormuthAuthor Commented:

I use borland c++ and g++.

I even want to use colors.

I thought POSIX was a standart to creatin threads ... ?
The POSIX standards include other functions besides thread functions.
Standard File, Terminal I/O, Files/Directories, and Process functions.

Check out tcgetattr() and tcsetattr()
The should be under <termios.h> header.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

It is not possible with cout (in general), the <iostream> library is *stream* based I/O.  This means that typically you can only move forward (sometimes backwards) in an I/O stream.  There is no concept of a terminal or positions on a terminal.

You could try something like ncurses, the gnu curses library (http://www.gnu.org/software/ncurses/ncurses.html), which would probably work with cygwin (see www.cygwin.com) on Windows.

>> platform independent and has no need of additional libraries

That's the problem here.  There _IS_NO_ platform independent way of doing platform DEPENDENT things.  That is the whole point behind things like CURSES.  They encapsulate the dependent things in such a way so as to remove the dependencies on the application program.
By the way, POSIX does NOT address this in any way.
>>I even want to use colors.

Another option is to use XLib or GNOME/GTK.
Both work on Unix and Linux, but as far as I know, they don't work on windows.

You might try looking to see if any one made libraries or classes to use GNOME/GTK code on windows.
>> they don't work on windows
Maybe, but TCL/Tk will, if you're planning on going into scripting.
You might get lucky with those other tool(kits), ever since Cygnus pulled their Cygwin dll trick Win32 has been flooded with ports of various Unix/Linux tools.

Haven't seen curses or ncurses on Win32 yet, but if someone has a link... For console IO that would surely be the most portable way.
Your best way will be to use ANSI codes on an ANSI compliant terminal output window.

A GotoXY would be:
sprintf(Buffer, "\x1B[%d;%df", XLoc, YLoc);
cout << "\x1B[";
cout << XLoc;
cout << ";";
cout << YLoc;
cout << "f";

Then just print your text:

Hello World!

Read about the ansi codes and see if this will do what you want it to do.  It is the best "platform independent" solution that I have found.

Ansi Codes:

#define Normal     "\x1B[0m"
#define Black   "\x1B[30;47m"
#define Red          "\x1B[31;40m"
#define Green   "\x1B[32;40m"
#define Yellow  "\x1B[33;40m"
#define Blue     "\x1B[34;40m"
#define Magenta "\x1B[35;40m"
#define Cyan    "\x1B[36;40m"
#define White   "\x1B[37;40m"
#define Cursor_Home     "\x1B[1;1f"
#define Clear_Screen     "\x1B[2J"

30   -      black characters
31   -      red characters
32   -      green characters
33   -      yellow characters
34   -      blue characters
35   -      magenta characters
36   -      cyan characters
37   -      white characters

40   -      black background
41   -      red background
42   -      green background
43   -      yellow background
44   -      blue background
45   -      magenta background
46   -      cyan background
47   -      white background

>>ANSI codes on an ANSI compliant terminal output window.

Yeah, right!  The question asks for a "platform independent and has no need of additional libraries" method. Please explain how requiring an ANSI compliant output window meets this specification!

Or are you just trying to grab points here with your inappropriate "answer" that is locking this question!

Please read and understand:


(Of course this is the C++ topic area where anything goes...)
No libraries are required for ANSI output.
Just an ANSI compliant shell, which Win9x, NT, 2000, Me all fit.  Also this will work on Unix if the emulation is VT100 or ANSI compatable.

Thus it is platform independent and requires no additional libraries.

jhance: No I am not trying to just grab points here with my "inappropriate answer".  Are you?
_YOU_ locked the question, not me.

If, if, if......  that's NOT platform independent in my book!

Hi c567591,
All of the experts here, for the most part have learn from other experts as to the proper etiquette for posting answer.

When posting an answer, it's considered improper etiquette to post an answer, after other experts have already posted possible answers, or have already made contributions to the question.

If you feel you have an answer, you can post it as a comment, and the questioner can convert your comment to an answer, if he/she thinks it?s correct or deserving of the awarded points.

There are some experts who never post answers as answer.  Instead, they post their answers as comments.  If you read the following link, you?ll see why this is the preferred method for many of our experts, including myself.


At the bottom of the above link, see the following section:
"Advice for Experts on Providing Solutions Through Comments or Answers"
Hey, ANSI... it hadn't occurred to me to use ANSI coding and it might be an option. Indeed many, many terminals support ANSI, though I think WinDos will require that driver to be loaded.

Some links on curses for Win32


Unix on Win32 links page
bormuthAuthor Commented:

Sorry for rejecting the answer ...

I think I have to respect that there is no strait forward answer to my question.

  Is it possible to split points to several persons ?

By the way I decied to use Curses on Unix and access the Win32 console directly.

I have problems with Win32 console. Have a look at

>> split points
You can ask in the Customer Support TA for help. They can do things like refunding your points so that you can post questions specifically for those you think were helpfull.

BTW, that link can not work, you need to post one with a qid=<whatever-number> in it.
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "Axter,jhance,Kangaroo,jasonclarke" comment(s) as an answer since you tried to award several experts.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please do not accept this comment as an answer!
bormuthAuthor Commented:

Sorry about forgetting this questions

   - Ingo
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now