#include #include #include #include #include using namespace std; int main(int argc, char* argv[]) { if (argc != 3) { cerr << "ERROR: No filename given." << endl; return 1; } ifstream f(argv[1]); if ( ! f ) { cerr << "ERROR: Could not open '" << argv[1] << "'." << endl; return 1; } string first, last; vector> v; while (f >> first >> last) { if ( first == argv[2] ) v.emplace_back(last, first); } f.close(); sort(v.begin(), v.end()); for ( pair const& i : v ) { cout << i.second << " " << i.first << endl; } return 0; }