Wow_Rasl

Untitled

Oct 10th, 2022
1,892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <fstream>
  6. #include <list>
  7. #include <ctime>
  8. const int NUM = 1000000;
  9. using namespace std;
  10. std::vector<int> vec_reader(const string& file_path, const int len) {
  11.     std::ifstream in;
  12.     in.open(file_path);
  13.     vector<int>ans;
  14.     if (in.is_open()) {
  15.         for (int i = 0; i < len; i++) {
  16.             int current;
  17.             in >> current;
  18.             ans.push_back(current);
  19.         }
  20.     }
  21.     return ans;
  22. }
  23.  
  24.  
  25. std::list<int> list_reader(const string& file_path, const int len) {
  26.     std::ifstream in;
  27.     in.open(file_path);
  28.     std::list<int>ans;
  29.     if (in.is_open()) {
  30.         for (int i = 0; i < len; i++) {
  31.             int current;
  32.             in >> current;
  33.             ans.push_back(current);
  34.         }
  35.     }
  36.     return ans;
  37. }
  38.  
  39. class TimeLogger {
  40. public:
  41.     std::ofstream out;
  42.  
  43.     TimeLogger(const string& file_path) {
  44.         out.open(file_path);
  45.     }
  46.  
  47.     void reset() {
  48.         current_time = time(0);
  49.         frozen_time = time(0);
  50.     }
  51.     time_t get_ctime() {
  52.         return current_time;
  53.     }
  54.     time_t get_ftime() {
  55.         return frozen_time;
  56.     }
  57.     void set_ftime(time_t time) {
  58.         frozen_time = time;
  59.     }
  60.     void log() {
  61.         if (out.is_open()) {
  62.             out << (time(0) - frozen_time);
  63.             out.close();
  64.         }
  65.     }
  66. private:
  67.     time_t frozen_time;
  68.     time_t current_time;
  69. };
  70.  
  71. int main() {
  72.     std::ofstream out;          // поток для записи
  73.     out.open("Database.txt"); // окрываем файл для записи
  74.     std::ifstream in;
  75.     in.open("DataBase.txt");
  76.     if (out.is_open())
  77.     {
  78.         for (int i = 0; i < NUM; i++) {
  79.             out << rand();
  80.             out << "\n";
  81.         }
  82.     }
  83.  
  84.     TimeLogger logger("Log.txt");
  85.     logger.reset();
  86.     logger.set_ftime(time(0));
  87.     cout << logger.get_ftime() << "\n";
  88.     vector<int>nums = vec_reader("DataBase.txt", 99999);
  89.     nums.push_back(20);
  90.     cout << logger.get_ftime() << " " << time(0);
  91.     logger.log();
  92.  
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment