#include // using std::ifstream #include // using std::cout, std::cerr #include // using std::vector #include // using std::string, std::getline int main() { std::vector keys; std::vector values; const char* fname = "house_repairs.txt"; std::ifstream input(fname); if(! input) { std::cerr << "unable to open " << fname << std::endl; return 1; } while(input) { /* first attempt to read an integer. If that fails, it must be a key */ int value; if(input >> value) values.push_back(value); else if(input.fail()) { input.clear(); std::string line; if(std::getline(input, line)) keys.push_back(line); } if(input.bad()) { std::cerr << "IO error" << std::endl; return 1; } } for(std::vector::iterator i = keys.begin(); i != keys.end(); ++i) (std::cout << "Got key " << *i).put('\n'); for(std::vector::iterator i = values.begin(); i != values.end(); ++i) (std::cout << "Got value " << *i).put('\n'); std::cout.flush(); return 0; }