fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <deque>
  4. #include <string>
  5.  
  6. struct Inv
  7. {
  8. std::string name;
  9. int price;
  10. int number;
  11. };
  12.  
  13. using namespace std;
  14.  
  15.  
  16. int main()
  17. {
  18. deque<Inv> dq_inv;
  19.  
  20. ifstream in("in.txt", ios::in);
  21.  
  22. if(!in)
  23. return 1;
  24.  
  25. {
  26. char buf[1000];
  27. in.getline(buf, 1000, '\n');
  28. in.getline(buf, 1000, '\n');
  29.  
  30. while(in)
  31. {
  32. Inv inv;
  33. in >> inv.name;
  34. in >> inv.price;
  35. in >> inv.number;
  36. if(!in.fail())
  37. dq_inv.push_back(inv);
  38. }
  39.  
  40. }
  41.  
  42.  
  43. {
  44. int counter = 0;
  45. for(deque<Inv>::iterator it(dq_inv.begin()); it != dq_inv.end(); ++it)
  46. {
  47. Inv &inv = *it;
  48. cout << "dq_inventory[" << counter << "]{";
  49. cout << "m_itemName=\"" << inv.name << "\",";
  50. cout << "m_itemPrice=" << inv.price << ",";
  51. cout << "m_itemAmount=" << inv.number << "}" << endl;
  52. ++counter;
  53. }
  54. }
  55.  
  56.  
  57. return 0;
  58. }
Runtime error #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Standard output is empty