It looks like you want line based reading. For this you probably want to use getline
consistently and then parse each line if you need to parse a number from then read line. It makes the input reading more consistent.
This way you don't have to manually scan for the end of each line to guarantee that the next read operation starts on a fresh line.
It also makes adding error handling for repeating input requests simpler.
e.g.
#include <string>
#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
int parse_integer(const std::string& input)
{
std::istringstream iss(input);
int result;
if (!(iss >> result))
{
// error - throw something?
}
return result;
}
int main()
{
int number;
std::string str;
int accountNumber;
std::string inputline;
std::cout << "Enter number: ";
if (!std::getline(std::cin, inputline))
{
// error - throw something?
}
number = parse_integer(inputline);
std::cout << "Enter name:";
if (!std::getline(std::cin, inputline))
{
// error - throw something?
}
str = inputline;
std::cout << "Enter account number:";
if (!std::getline(std::cin, inputline))
{
// error - throw something?
}
accountNumber = parse_integer(inputline);
return 0;
}