Click here to Skip to main content
11,934,389 members (40,943 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++
in c++ how do you combine code like

press any button to continue

How are you doing?
press any button to continue

and so on

Posted 29-Apr-11 15:56pm
Edited 29-Apr-11 18:41pm
SAKryukov 29-Apr-11 21:13pm
This is beyond the good and evil!
Hans Dietrich 29-Apr-11 23:50pm
I look at it as *before* the good and evil.

I mean, there was a time when I didn't know what ASCII was. I know, I know; a little removed from COM interfaces and .NET interop. I'm not even sure if there are any articles on CodeProject that would help the OP. And if there were, they would probably be downvoted out the wazoo, what with our lovely voting system.
SAKryukov 30-Apr-11 0:04am
The problem is not voting or even CodeProject level or a student's level. I know pretty well how people who did not yet get what is a variable or function is, how they think of things and try to learn. You know, I find most of them reasonable enough. They mostly adequately evaluate their knowledge and are able to ask comprehensible questions which worse answering. What we see here is something else...
Hans Dietrich 30-Apr-11 0:27am
I agree. This is a level of knowledge that comes before questions such as, How do I play a WAV file? We were all here at one point, so we shouldn't be surprised to find others here now. :)
SAKryukov 30-Apr-11 1:25am
I was always amazed why so many people (except those familiar with mathematics and the idea of "proof", "axiom", etc.) think that real-life statements are classified just into "true" and "false", failing to understand that there is one more class (again in real-life language) which can be called "makes no sense". Failing to recognize such thing usually leads to making a lot of statements from this third class :-)

Same story with questions.
I'm very afraid to say so, but often the same story with "functional requirements". :-<
Karthik. A 29-Apr-11 22:26pm
@SA - nice one!!!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is a wild guess, but if you mean how do you pause for a key stroke, then look up _getch on MSDN.[^]
Albert Holguin 30-Apr-11 14:19pm
my 5
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

What you are asking about is a type of man-machine interface. In human communications, when you say Hello, you pause to wait for the other person to respond. In the same way, there are two steps involved in constructing an interface with a computer:

1. Output (display) a string, such as Hello.

2. Wait for a response; a keystroke, or a string, or some kind of user selection.

On PCs running Windows or Unix/Linux, there is a standard library of functions that allow you to do these two things. It is called the "C RunTime", or CRT for short.

Using CRT functions, it is possible to do what you are asking about. We use the CRT function "puts" to display a string, and then use the CRT function "_getch" to wait for a keystroke (a "button" as you call it).

We can repeat these two steps as many times as we want.

The following code can be pasted into a Visual Studio project and compiled if you would like to see it in action:
// console1.cpp : Defines the entry point for the console application.
#include <stdio.h>
#include <conio.h>
int main(int argc, char* argv[])
	// ask the first question
	puts("Press any button to continue...\n");
	// wait for key press
	// ask the next question
	puts("How are you doing?\n");
	puts("Press any button to continue...\n");
	// wait for key press
	// etc.
	return 0;
Albert Holguin 30-Apr-11 14:19pm
Hard to interpret what the OP wants, but this may be it... my 5 :)
Hans Dietrich 30-Apr-11 15:32pm

Some people would associate lack of knowledge with being stupid, but I am willing to believe this was an honest question, from someone with little exposure to the subject. There's no reason not to encourage people like this.
Albert Holguin 30-Apr-11 20:46pm
I didn't call him stupid, just hard to interpret what he wants (not a well phrased question). :)
Hans Dietrich 30-Apr-11 21:26pm
I know you didn't; but from the 1-votes other people obviously thought that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 30 Apr 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100