You might try something like this:
Code:int rn; std::string name, ccnum; std::ifstream fin("input.txt"); if (!fin) { std::cerr << "Error ...\n"; std::exit(EXIT_FAILURE); // you may want to exit, or not... } while (fin >> rn) { fin >> name; // Can the name have spaces? Then this won't work. fin >> ccnum; // With the appropriate Customer ctor you could do this: hotel.room[rn].assignCustomer(Customer(name, ccnum)); // If hotel.room is a vector, you're better to use at() instead of []. }