-
Unable to pause program
Hello I have been programming for a few days now and I have runned inn to a little problem. the cin.get(); won't pause my program.
I have tried to use cin.ignore(); above the cin.get() to make it pause but with no sucsess :frown:
i have also tried to use system("pause");
the compiler I use is called "Microsoft Visual c++ 2010"
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello world\n";
cout << "Here is 5: " << 5 << "\n";
cout << " the manipulator endl writes a new line to the screen." <<
endl;
cout << " Here is a very big number:\t" << 70000 << endl;
cout << " Here is the sum of 8 and 5:\t" << 8+5 << endl;
cout << " Here's a fraction:t\t" << (float) 5/8 << endl;
cout << " and a very very big number:\t" << (double) 700 * 700 <<
endl;
cout << "Don't forget to replace Jesse Liberty with your name...\n";
cout << "shacko is a C++ programmer!\n";
cin.get();
return 0
}
-
There's no semicolon after the "return 0". I don't know if this was a copy-paste error, but it's possible that you were just running the last successful build (presumably from before you inserted the cin.get()).
If that is the issue, I'd recommend changing this setting for future use:
In the Projects and Solutions options: Build and Run -> On Run, when build or deployment errors occur -> Prompt To Launch
Then VS will bring a message box up if the build fails.
-
You can type getchar();it does the same job.
-
The real question is, why do you want to pause the program? Launch it with Ctrl+F5 instead of just F5 and Visual Studio will keep the console open for you.
-
i use. i dont know if they work very well but they do the job for me...maybe they will help you untill you learn a better method:D
Code:
cin.ignore();
cin.get();
-
CornedBee just mentioned a better method right above your reply!