Solved

gotoxy for cout ?

Posted on 2001-06-11
18
1,071 Views
Last Modified: 2012-05-04


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....

0
Comment
Question by:bormuth
  • 4
  • 4
  • 3
  • +4
18 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6177779
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.
0
 

Author Comment

by:bormuth
ID: 6177844

I use borland c++ and g++.

I even want to use colors.

I thought POSIX was a standart to creatin threads ... ?
0
 
LVL 30

Expert Comment

by:Axter
ID: 6177918
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.
0
 
LVL 9

Accepted Solution

by:
jasonclarke earned 100 total points
ID: 6178085
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.

0
 
LVL 32

Expert Comment

by:jhance
ID: 6178333
>> 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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6178335
By the way, POSIX does NOT address this in any way.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6178381
>>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.
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 6178683
>> 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.
0
 
LVL 1

Expert Comment

by:c567591
ID: 6181359
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);
or
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

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 32

Expert Comment

by:jhance
ID: 6181391
>>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:

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

(Of course this is the C++ topic area where anything goes...)
0
 
LVL 1

Expert Comment

by:c567591
ID: 6181903
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?
0
 
LVL 32

Expert Comment

by:jhance
ID: 6181966
_YOU_ locked the question, not me.

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

0
 
LVL 30

Expert Comment

by:Axter
ID: 6182043
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.

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

At the bottom of the above link, see the following section:
"Advice for Experts on Providing Solutions Through Comments or Answers"
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 6183082
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

http://dmoz.org/Computers/Software/Operating_Systems/Unix/Win32/
http://virtunix.itribe.net/files/gsar/pdcurses-2.3b-win32.tar.gz
http://infoservice.lg.ua/~paul/devel/pdcurses_mingw32.html

Unix on Win32 links page
http://dmoz.org/Computers/Software/Operating_Systems/Unix/Win32/
0
 

Author Comment

by:bormuth
ID: 6190159

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

http://www.experts-exchange.com/jsp/qYourQuestion.jsp?jsessionid=127575992510748836
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 6192418
>> 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.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6814555
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!
======
Werner
0
 

Author Comment

by:bormuth
ID: 6814596


Sorry about forgetting this questions


   - Ingo
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now