fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct airport {
  5. std::string code;
  6. std::string location;
  7. };
  8.  
  9. std::istream& operator>>(std::istream& in, airport& a) {
  10. in >> a.code; //read until first whitespace
  11. std::getline(in, a.location); //read until end of line;
  12. return in;
  13. }
  14.  
  15. std::ostream& operator<<(std::ostream& out, const airport& a) {
  16. return out << a.code << ' ' << a.location << '\n';
  17. }
  18.  
  19. int main() {
  20. airport newairport;
  21. std::vector<airport> myairports;
  22. while(std::cin >> newairport)
  23. myairports.push_back(newairport);
  24. for(int i=0; i<myairports.size(); ++i)
  25. std::cout << myairports[i];
  26. return 0;
  27. }
Success #stdin #stdout 0.02s 2864KB
stdin
AQN  Aguadilla, Puerto Rico
BQN  Aguailla, Puerto co
CQN  Aguadla, Puto Rico
DQN  Aguilla, PuertRico
stdout
AQN   Aguadilla, Puerto Rico
BQN   Aguailla, Puerto co
CQN   Aguadla, Puto Rico
DQN   Aguilla, PuertRico