Author Topic: C++ Functions  (Read 1946 times)

Kintaro

  • Member
  • **
  • Posts: 6,545
  • Kudos: 255
  • I want to get the band back together!
    • JohnTate.org
C++ Functions
« on: 16 August 2002, 18:00 »
Where can I get some more functions for C++ rather then the ones i know which are cout and cin.

Basicly i want to know how to do things like locate text in certain parts of the creen, change text color, ect, ect... where?

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #1 on: 16 August 2002, 18:35 »
Assuming you are in UNIX/Linux and assuming you do not want to do this graphically but in a shell/terminal then you probably want to look at the "ncurses" libraries.  And there is a reason for the name "curses", you'll find out.    

Here is a google search for "ncurses c++":
http://www.google.com/search?hl=en&ie=ISO-8859-1&q=ncurses+c%2B%2B

[ August 16, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Kintaro

  • Member
  • **
  • Posts: 6,545
  • Kudos: 255
  • I want to get the band back together!
    • JohnTate.org
C++ Functions
« Reply #2 on: 16 August 2002, 19:47 »
ncurses isnt quite what im looking for...

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #3 on: 16 August 2002, 19:57 »
Hmmm, well ncurses does exactly what you were asking for. You can locate your cursor on the screen, position it anywhere on the screen, change color of text etc.  Again, that is for terminals (virtual terminals, xterm, kterm, etc). It's what gives programs like RedHat's text based "setup" program or the non-X mode of linuxconf the ability to do color menuing in a terminal/shell. I used to do a lot of curses based programming on RS/6000s to give dialin users (not internet/ppp) a menuing system for running applications and downloading data.  But that was 7 or 8 years ago so modems were only capable of aroun 14.4 at the time and since curses is text based menuing it was very fast.

What are your other requirements?  Did you really want to do this within a graphical X app?  If so, ncurses is definitely not the library. Or did you mean something like the svgalib, which allows you to do graphics (in graphics modes supported by your video card, not text graphics) outside of X?

If you want to do this in X then there are hundreds of libraries in which this can be accomplished including the X libraries themselves (although you would likely want to use a higher level graphics library).

[ August 16, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Kintaro

  • Member
  • **
  • Posts: 6,545
  • Kudos: 255
  • I want to get the band back together!
    • JohnTate.org
C++ Functions
« Reply #4 on: 16 August 2002, 20:56 »
I am new too C++, i read the manpage and it was not very explainatory.

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #5 on: 16 August 2002, 21:06 »
Well give me an example of what you wish to accomplishand then I can help you out further.

Examples:
- I need to do text/terminal based menus in C++
-- I need to be able to position the cursor and draw text
- I want to do text/ascii based animations in C++
- I need to do X based menus in C++
- I want to create an X based game in C++
etc..

Also, there is a higher level ncurses based library and programs that come with most Linux distros called "dialog" that I used to use for creating menus in scripts (much like Norton's Batch Enhancer for DOS "BE").  I believe you can call the dialog functions from your C/C++ programs using those libraries (#include <dialog.h> ;) . See "man dialog" for the command line dialog utility for use in scripts. There are samples in /usr/share/doc/dialog*/samples directory. And if it looks like something that you would like to do within your C++ code I can get you some programming references for using the library...

At any rate, I need more input as I have not yet mastered the ability to read minds...
Someone please remove this account. Thanks...

Kintaro

  • Member
  • **
  • Posts: 6,545
  • Kudos: 255
  • I want to get the band back together!
    • JohnTate.org
C++ Functions
« Reply #6 on: 16 August 2002, 21:31 »
What i need to accomplish is basicly what locate does in basic (which is a shit language)

for example:
Code: [Select]
that would put an x at row 13 and coulumn 2.

Just things like that and:

Code: [Select]

that would print "BLAH" to the standard output in bright white....

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #7 on: 16 August 2002, 21:44 »
ncurses provides very similar functions (much like the CRT unit in TP).  I don't believe there are any built-in default C++ functions for this. See this HOWTO:

http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/
Someone please remove this account. Thanks...

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #8 on: 16 August 2002, 21:51 »
ncurses provides very similar functions (much like the CRT unit in TP).  I don't believe there are any built-in default C++ functions for this. See this HOWTO:

http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/

Code: [Select]

or

Code: [Select]

or a C example:
Code: [Select]

In RedHat if you want to compile/run the above you need to make sure you have the "ncurses-devel" RPM installed and to compile:

gcc -lncurses -o myncprog myncprog.c

[ August 16, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Kintaro

  • Member
  • **
  • Posts: 6,545
  • Kudos: 255
  • I want to get the band back together!
    • JohnTate.org
C++ Functions
« Reply #9 on: 16 August 2002, 22:34 »
Cool it works, i wrote my own liabary simlar to curses in basic... see my semo, which is "Microsoft .NET CLONE" its funny, and well coded for such a crap language.

here:
x11.150m.com/dotnet.html

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #10 on: 16 August 2002, 22:42 »
I'm starting to get the idea that you want those cursor functions to use for C++ in DOS/Windows.  I assumed you were learning C++ in Linux.  I don't believe there is a DOS version of ncurses.  You will likely need to find a DOS library that provides that functionality.

If you have a UNIX version of your program I would be happy to check it out. Not going to load up Windows...
Someone please remove this account. Thanks...

Kintaro

  • Member
  • **
  • Posts: 6,545
  • Kudos: 255
  • I want to get the band back together!
    • JohnTate.org
C++ Functions
« Reply #11 on: 17 August 2002, 07:11 »
So is the move(x,y) a curses thing?
Whats clear screen without curses btw?

Kintaro

  • Member
  • **
  • Posts: 6,545
  • Kudos: 255
  • I want to get the band back together!
    • JohnTate.org
C++ Functions
« Reply #12 on: 17 August 2002, 07:18 »
No im talking Linux/Unix (Linux and FreeBSD) Im just used to programming in those languages/platforms.

I can write simple things in C++, eg a thing that prints out numbers until it overflows. (Gets quite high in FreeBSD) So yes im programming in Linux, If theres no version of curses for dos ill just write one.

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #13 on: 17 August 2002, 08:56 »
What compiler are you using for DOS?  GCC?
Someone please remove this account. Thanks...

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C++ Functions
« Reply #14 on: 17 August 2002, 21:19 »
quote:
Originally posted by Ex Eleven / b0b:
So is the move(x,y) a curses thing?
Whats clear screen without curses btw?



Well, the system command is "clear" or "tput clear" and you can always cheat and do a system call to clear the screen without using curses:

system("clear");

or in DOS

system("cls");

otherwise you would have to use a screen library (curses/ncurses/etc in Linux or some sort of CRT library in DOS, I don't know what that would be).  

Another way to do it is to write directly to 0xB800 which is the base address for video RAM.  I used to do this in DOS, don't know if it will work in a Windows command prompt.  But basically you have two bytes for each char on the screen.  One is the char and one is the attibute if I recall correctly.  So for an 80x25 screen you have 4000 bytes starting at 0xB800 (I think that was the right base address).  This may require some ASM and probably is a little much for what you want to do. Since you can have a command prompt with a size different than 80x25 I don't know that this method will work inside of Windows.

But hopefully someone else on here is more familiar with text based C++ programming in DOS.  I haven't done any DOS screen programming in a LONG time so I am pulling stuff out of my ass now.  When I did this type of stuff in DOS I was using Turbo Pascal and it had the CRT library with all the functions similar to ncurses. gotoxy(), clrscr(), etc...

Might actually be easier to make it a Windows/Xwindows app using a cross platform library like QT or Tk etc.  Text based screen programming can sometimes be more of a bitch than graphics programming.
Someone please remove this account. Thanks...