Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6.  
  7. int main()
  8. {
  9. std::ifstream File("F:/Folder/input.vgp", std::ifstream::in | std::ifstream::binary);
  10. std::ofstream OutFile("F:/Folder/output.txt");
  11.  
  12. unsigned int SizeRead = 0;
  13.  
  14. while (1)
  15. {
  16. if (File.is_open())
  17. {
  18. std::vector<int> AverageResults;
  19. int ResultsCount;
  20. File.seekg(0, std::ios::end);
  21. unsigned int Size = File.tellg();
  22. File.seekg(SizeRead, std::ios::beg);
  23. if (SizeRead < Size)
  24. {
  25. File.read((char*)& ResultsCount, sizeof(int));
  26. int Amount = 0;
  27. for (int ResultIndex = 1; ResultIndex <= ResultsCount; ResultIndex++)
  28. {
  29. int ResultValue = 0;
  30. File.read((char*)& ResultValue, sizeof(int));
  31. Amount += ResultValue;
  32. }
  33. AverageResults.push_back(Amount / ResultsCount);
  34. }
  35.  
  36. SizeRead = File.tellg();
  37.  
  38. OutFile.open("F:/Folder/output.txt", std::ofstream::end);
  39. if (OutFile.is_open())
  40. {
  41. for (int i = 0; i < AverageResults.size(); i++)
  42. {
  43. std::string str = std::to_string(AverageResults[i]);
  44. str += "\n";
  45. OutFile << str;
  46. }
  47. OutFile.close();
  48. }
  49. }
  50. else
  51. {
  52. File.open("F:/Folder/input.vgp", std::ifstream::in | std ::ifstream::binary);
  53. }
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement