Possible Duplicate:
c++ cin input not working?
I have been trying to input a string after an integer using the following code in c++.
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n;
char inp[10];
cin>>n;
//fflush(stdin);
cin.getline(inp,10);
cout<<inp;
return 0;
}
When i am compiling and running above code, the program is prompting for input only once and printing nothing. I am using g++ for compiling the code.
Also when i uncommented the line
fflush(stdin)
(clearing input buffer), the o/p of program remains the same. I don’t understand what is going on here.
1 Answer