#include // using std::ifstream #include // using std::cout, std::cerr #include // using std::vector #include // using std::string, std::getline #include // using std::pair int main() { 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) { std::string header; int value; if(std::getline(input, header) >> value >> std::ws) values.push_back(std::make_pair(header, value)); } if(! input.eof()) { std::cerr << "IO error after " << values.size() << " key value pairs" << std::endl; return 1; } for(std::vector >::iterator i = values.begin(); i != values.end(); ++i) { (std::cout << "Got " << i->first).put('\t'); (std::cout << i->second).put('\n'); } std::cout.flush(); return 0; }