1.

Solve : C++ pause?

Answer»

OK, I'm trying to make the long jump from Visual Basic to C++. I'm reading a few online tutorials, and C++ isn't the monster I remember (if I can look at a C++ code block and say, "hey, that's just like JavaScript!", I MAY have it made). However, it's still a little confusing.

I'm starting with command-line based programs at the moment, just a few "hello world" variants. I want to pause the program so I can actually see what's going on. One person recommends including stdlib.h and using the line

Code: [Select]system("PAUSE");
But it won't pause. I've compiled it three times and ran it as many, no syntax errors, but it's just not stopping long enough to READ. What can I do to make it pause?

Using Dev C++ 4.9.9.2.I know next to nothing about C++, but Google and I are thisclose

Code: [Select] #include <stdio.h>

int main()
{
printf ("Press ENTER to continue.\n");
getchar ();
return 0;
}

OR

Code: [Select] #include <stdlib.h>

int main()
{
system ("pause");
return 0;
}

8-)Sometimes, simple print statements can also help you debug your program. Or you could try the C++ exception catching. http://cplus.about.com/od/beginnerctutorial/l/aa122202a.htmBut this program is far too simple to have such huge difficulties, you'd think.

dl65, I too used Google. I'm POSTING because it didn't work.

The full source code (nobody laugh, I'm on a tutorial):

Code: [Select]#include <iostream.h>
#include <stdlib.h>

int main()
{
int myNumber;
long myNumber2 = 5;
char myCharacter;
char mycharacter2 = 'c';
bool myBoolean;
bool myBoolean2 = true;


myNumber = 3678;
myCharacter = 'a';
myBoolean = false;

cout << "mynumber = " << myNumber << endl;
cout << "mynumber2 = " << myNumber2 << endl;

cout << "mycharacter = " << myCharacter << endl;
cout << "mycharacter2 = " << myCharacter2 << endl;
system("PAUSE");
return 0;
}

It isn't pausing...an alternative
http://cpp.codenewbie.com/articles/cpp/1437/systemPAUSE-Page_1.htmlThe solution is simple.

char temp; (or whatever) where you define your variables.

then at the end

cin >> temp;

The program will pause and wait for you to enter in some letters. Just press anything and hit enter to end the program.


Just so you know, cin is where the user enters in data. For example cin >> temp, I type in 'a', and temp now = 'a'Quote

an alternative
http://cpp.codenewbie.com/articles/cpp/1437/systemPAUSE-Page_1.html


Thank you. What? You are going to do THAT?

All you need to do is

char temp;
cin >> temp;

at the end of your program.

Simple!Oh, OK. I thought that... well... whatever. That WORKS just as well, if not better.

Like I said, sorry, this is really new to me. It's not easy LEARNING this stuff.

EDIT: ACK! IT'S THE P2K (Post 2K) VIRUS!!!

Seriously, look at it. It's calling me an expert, for some reason.


Discussion

No Comment Found