Visual Studio 2013; Input won't work

I'm using sample code from this site, but can't get the program to do anything with input. If I type, whatever I type just shows up. If I type 8, all I see is this:

"Please enter an integer value: 8"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// i/o example

#include <iostream>
using namespace std;

int main()
{
	int i;
	cout << "Please enter an integer value: ";
	cin >> i;
	cout << "The value you entered is " << i;
	cout << " and its double is " << i * 2 << ".\n";
	return 0;
}


It must be a problem with the settings. I've tried using and empty template and using a win32 console application template (with the "empty" bot checked in the wizard, as per the tutorial on this site).
Are you pressing enter? Haha. Because if you're not then of course all you will see is that statement along with the number you just typed.
Last edited on
But enter closes the program. How do I configure it so that enter doesn't close the program? I have Visual Studio 2013 for Desktop and Windows 8.1 64-bit as my OS. I am using the Local Windows Debugger in Debug mode with Win32 platform.

I tried both the enters because I know in some programs that makes a difference. Both close the program.
The program gets closed when you press enter, but it still reads and prints data correctly.
Think about what happens:
Your program reads input, prints the values, and what happens once it reaches
return 0;?
It ends, it quits, it gets closed.
But, it still prints everything correctly. It simply gets closed so fast you can't see it.
You just need it to wait for another input.
Put cin.get(); before return 0; and give it another try.
cin.get(); will wait for you to press Enter.
Last edited on
Topic archived. No new replies allowed.