fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <vector>
  5. #include <string>
  6. using namespace std;
  7. struct name_of_struct
  8. {
  9. string datum;
  10. int max;
  11. double power;
  12. int min;
  13. };
  14. int main()
  15. {
  16. vector<name_of_struct> v;
  17.  
  18. // no files on ideone, using string source
  19. // ifstream f("test.txt");
  20. istringstream f("26.08.2011;0000123;4.567;0000345;\n"
  21. "27.08.2011;0000223;5.567;0000400;");
  22.  
  23. string line;
  24. while(getline(f, line))
  25. {
  26. istringstream str(line);
  27. name_of_struct item;
  28. getline(str, item.datum, ';');
  29. char c;
  30. str >> item.max >> c >> item.power >> c >> item.min;
  31. v.push_back(item);
  32. }
  33.  
  34. for(size_t n = 0; n < v.size(); ++n)
  35. {
  36. std::cout << "structure number " << n << ": "
  37. << v[n].datum << ", " << v[n].max << ", "
  38. << v[n].power << ", " << v[n].min << '\n';
  39. }
  40. }
  41.  
Success #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
structure number 0: 26.08.2011, 123, 4.567, 345
structure number 1: 27.08.2011, 223, 5.567, 400