fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. struct line{
  8. char f1,f5; // give them mneaningful names
  9. int f2,f3,f4;
  10. friend std::istream &operator>>(std::istream &is, line &l) {
  11. is >> l.f1;
  12. is >> l.f2;
  13. is >> l.f3;
  14. is >> l.f4;
  15. is >> l.f5;
  16. return is;
  17. }
  18. };
  19.  
  20.  
  21. int main() {
  22.  
  23. string input = "J 123 7 3 M\nK 123 7 3 E\nH 16 89 3 M";
  24. stringstream ss(input);
  25. vector<line> v;
  26. line current;
  27.  
  28. while(ss >> current){
  29. v.push_back(current);
  30. }
  31. for (auto &val: v){
  32. cout<< val.f1 << endl;
  33. }
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
J
K
H