Reputation: 43
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
const int Length = 61;
void getinput (char []);
int main()
{
char a[Length];
char b[Length];
getinput(a);
getinput(b);
}
void getinput (char input[]){
cout << "Enter Input: ";
cin.get(input, 60);
cout << "You Entered " << input <<endl;
}
When I run this code i can not input my second input it? I dont understand All i have done is just call the same function twice.
This is what gets output:
Enter Input: Hi
You Entered: Hi
Enter Input: You Entered
Upvotes: 0
Views: 197
Reputation: 17713
That was because cin
buffered input
cin.get(input, 60);
The second call would interpret the new line character left over from the first first call as its input.
To prevent such error, you may use getline
instead:
std::cin.getline (input,60);
Upvotes: 2