ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If you want to implement a true, "Press any key to continue..." prompt, you will first have to change the way the unix terminal handles input. The standard buffered IO in un*x doesn't send the buffer to the program until a EOF or newline is entered. That is why you have to press enter if you use cin.get() or getchar, or the like. Raw (unbuffered or cooked mode) IO sends input as it is recieved, and this is what you want. You can change terminal attributes by using the stty command from inside your program. For simplicity I used the C function, system(), inside the sample code below to execute my terminal commands, but in practice you should learn to use the C exec family of functions. They are more secure and robust than system(). The code below enters raw mode, waits for one character, enters back into normal "cooked" mode, and then exits.
Code:
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
//Output prompt
cout << "Press any key to continue..." << endl;
//Set terminal to raw mode
system("stty raw");
//Wait for single character
getchar();
//Reset terminal to normal "cooked" mode
system("stty cooked");
//And we're out of here
return 0;
}
Distribution: Got RH9 (Shrike) from Distro that came with Red Hat Linux 9 Bible - Christopher Negus
Posts: 8
Rep:
jinksys and others:
8/23/04 14:39 MST
Some of us are just getting to this now, a year after jinksys post. This information is still valuable and a reliable reference for those who follow.
When learning a new language I flip between reference docs like man files, info files and books. Then flip to sample code snippets that people here freely post. Between these two, I will have this language mastered in two months.
Thanks kev82 for that link to: www.cplusplus.com This site has tons of stuff on the STL that I couldn't find anywhere. That site will keep me busy for couple of months.
Thanks everyone.
Well, this was a useless, generic thank you of a post, sorry, it has no useful information. Carry on elsewhere.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.