LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2004, 05:35 AM   #1
cool_ashwin22
LQ Newbie
 
Registered: Jul 2004
Distribution: fedora1
Posts: 23

Rep: Reputation: 15
how to get getch() working with c++


My Code

#include<iostream.h>
#include<stdlib.h>
#include<curses.h>
int main(void)
{
system("clear");
cout<<"Hello World"<<endl;
getch();
}

I get an error with this code for getch() What Should i do pls help
 
Old 08-03-2004, 06:28 AM   #2
Ephraim
LQ Newbie
 
Registered: May 2002
Posts: 11

Rep: Reputation: 0
Why using getch ?

Code:
void break() {
      cout.flush();
      char s[1];
      cin.get(s, 1);
}
This does the same

By the way, if you really want to get a solution for your prob.
Post the error what you get!!!!!!!!!!


Ciao Ephraim
 
Old 08-03-2004, 10:45 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
...or use getchar(), which doesn't need ncurses. (I bet your error was about ncurses).

When using getchar, remove "#include <curses.h>"
and put "#include <stdio.h>"

But Ephraim's solution i nicer, because it's a C++ solution (getchar and getch are plain C).
 
Old 08-03-2004, 10:58 AM   #4
rkef
Member
 
Registered: Mar 2004
Location: bursa
Posts: 110

Rep: Reputation: 15
Please see my reply to someone with a similar problem: g++/ncurses

I believe that will help.

This assumes you weren't just using ncurses for the "<press any key to continue>" functionality; if you were, just follow Ephraim's solution.

Also, if you <i>do</i> want ncurses, you may want to turn echo off and some other things (I haven't used ncurses in awhile, so I can't remember all the options... cbreak or something?).

Also, is getch() really unique to C, or just unique to ncurses?

Last edited by rkef; 08-03-2004 at 11:00 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
clrscr(); and getch(); not working in kdevelop Onemessedupjedi Programming 11 04-26-2010 12:14 PM
Where is getch()....... rajsun Programming 2 03-28-2005 11:40 AM
getch function prasad514 Programming 6 01-03-2005 11:48 AM
Help with getch... darkarcon2015 Programming 4 09-12-2004 08:48 AM
getche() and getch() kamransoomro84 Programming 2 05-09-2004 12:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration