fork download
  1. #include <iostream>
  2. #include <ostream>
  3. #include <istream>
  4. #include <ostream>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <string>
  8. #include <iomanip>
  9.  
  10. void GetOutputFileStream(std::ofstream * fout, std::string filename)
  11. {
  12. fout->open(filename, std::ios::out);
  13. }
  14. void PrintStatistics(std::ostream & fout,
  15. int numUsed,
  16. int numNew,
  17. double newTotalPrice,
  18. double newTotalMileage,
  19. double usedTotalPrice,
  20. double usedTotalMileage)
  21. {
  22.  
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.  
  29. double newTotalPrice = 33333;
  30. double newTotalMileage = 44444;
  31. double usedTotalPrice = 22222;
  32. double usedTotalMileage = 99999;
  33. int numUsed = 2;
  34. int numNew = 3;
  35. std::ofstream fout; // 'f'ile out - fout
  36. std::string filename = "statistics.txt";
  37. GetOutputFileStream(&fout, filename);
  38. // Print to screen
  39. PrintStatistics(std::cout,
  40. numUsed,
  41. numNew,
  42. newTotalPrice,
  43. newTotalMileage,
  44. usedTotalPrice,
  45. usedTotalMileage);
  46. // Print to file
  47. PrintStatistics(fout,
  48. numUsed,
  49. numNew,
  50. newTotalPrice,
  51. newTotalMileage,
  52. usedTotalPrice,
  53. usedTotalMileage);
  54.  
  55.  
  56. std::cout << "Press ENTER to continue";
  57. std::cin.get();
  58.  
  59. return 0;
  60. }
  61.  
  62.  
  63.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
Press ENTER to continue