Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <list>
- #include <ctime>
- const int NUM = 1000000;
- using namespace std;
- std::vector<int> vec_reader(const string& file_path, const int len) {
- std::ifstream in;
- in.open(file_path);
- vector<int>ans;
- if (in.is_open()) {
- for (int i = 0; i < len; i++) {
- int current;
- in >> current;
- ans.push_back(current);
- }
- }
- return ans;
- }
- std::list<int> list_reader(const string& file_path, const int len) {
- std::ifstream in;
- in.open(file_path);
- std::list<int>ans;
- if (in.is_open()) {
- for (int i = 0; i < len; i++) {
- int current;
- in >> current;
- ans.push_back(current);
- }
- }
- return ans;
- }
- class TimeLogger {
- public:
- std::ofstream out;
- TimeLogger(const string& file_path) {
- out.open(file_path);
- }
- void reset() {
- current_time = time(0);
- frozen_time = time(0);
- }
- time_t get_ctime() {
- return current_time;
- }
- time_t get_ftime() {
- return frozen_time;
- }
- void set_ftime(time_t time) {
- frozen_time = time;
- }
- void log() {
- if (out.is_open()) {
- out << (time(0) - frozen_time);
- out.close();
- }
- }
- private:
- time_t frozen_time;
- time_t current_time;
- };
- int main() {
- std::ofstream out; // поток для записи
- out.open("Database.txt"); // окрываем файл для записи
- std::ifstream in;
- in.open("DataBase.txt");
- if (out.is_open())
- {
- for (int i = 0; i < NUM; i++) {
- out << rand();
- out << "\n";
- }
- }
- TimeLogger logger("Log.txt");
- logger.reset();
- logger.set_ftime(time(0));
- cout << logger.get_ftime() << "\n";
- vector<int>nums = vec_reader("DataBase.txt", 99999);
- nums.push_back(20);
- cout << logger.get_ftime() << " " << time(0);
- logger.log();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment