Mixing formatted and unformatted input is fraught with problems. In your particular case, this line:
std::cin >> n;
consumes the number you dialed but leaves '\n' in the input stream.
Subsequently, this line:
cin.get (a, 10);
does not consume data (since the input stream still points to '\n' ). The next call also does not use data for the same reasons, etc.
Then the question arises: "How can I use '\n' ?" There are several ways:
You can read one character and throw it away:
cin.get();
You can read one whole line, regardless of length:
std::getline(std::cin, some_string_variable);
You can ignore the rest of the current line:
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
As some related tips, I would never use std::istream::get(char*, streamsize) . I always prefer: std::getline(std::istream&, std::string&) .
source share