fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4.  
  5. struct Item
  6. {
  7. std::string name;
  8. int iid;
  9. double value;
  10. };
  11.  
  12.  
  13. int main()
  14. {
  15. std::vector<Item> vi(5);
  16.  
  17. std::ifstream fs;
  18.  
  19. fs.open("data.txt");
  20.  
  21. while (fs.is_open() && !fs.eof())
  22. {
  23. std::string name;
  24. int iid;
  25. double value;
  26.  
  27. fs >> name >> iid >> value;
  28.  
  29. vi.push_back(Item{ name, iid, value });
  30. }
  31.  
  32. fs.close();
  33.  
  34. for (auto x : vi)
  35. {
  36. std::cout << x.name << ' ' <<
  37. x.iid << ' ' <<
  38. x.value << std::endl;
  39. }
  40.  
  41. return 0;
  42. }
  43.  
  44.  
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
 0 0
 0 0
 0 0
 0 0
 0 0