user3131535
user3131535

Reputation: 33

cin crashes C++ program

I feel like this is a very rudimentary problem, but I can't seem to get cin working.

Using code as simple as this:

#include <iostream>
using namespace std;

int main ()
{
    int i;
    cout << "Enter a number: ";
    cin >> i;   
    cout << i;
}

causes the program to crash. It compiles perfectly fine, but when I run it I get the program has stopped working dialog box. I'm using MinGW with the g++ commands to compile my code. I'm also running windows 8.1 if that has any effect whatsoever.

Upvotes: 1

Views: 1776

Answers (1)

Bhoot
Bhoot

Reputation: 2633

The code is perfectly fine. The issue is with the compiler. This generally happens because of the misconfiguration of linking files (DLL's). It is recommended that you uninstall the current installation and re-install the software by following the installation instructions. If you are looking for bundled alternatives then you can try Code::Blocks - http://www.codeblocks.org/.

Upvotes: 1

Related Questions