Advertisement
Frumkin

Untitled

Jul 1st, 2021
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <filesystem>
  3. #include <fstream>
  4. #include <chrono>
  5. #include <string>
  6. #include <vector>
  7. #include <cctype>
  8.  
  9. #define debug(x) std::cout << x << std::endl
  10. #define error(x) std::cerr << x << std::endl
  11.  
  12. #pragma region File Streaming
  13.  
  14. const std::string DIRECTORY = std::filesystem::current_path();
  15. const std::string SOURCE_FILE = "source";
  16.  
  17. void ReadFromFile(const std::string& path, std::string& output) {
  18.     std::getline(std::ifstream(path), output, '\0');
  19. }
  20.  
  21. void WriteToFile(const std::string& path, const std::string& data) {
  22.     std::ofstream stream(path, std::ofstream::out);
  23.  
  24.     if (stream.is_open()) {
  25.         stream << data;
  26.         stream.close();
  27.     } else {
  28.         error("Could not open " + path + ".");
  29.     }
  30. }
  31.  
  32. int main() {
  33.     auto start = std::chrono::high_resolution_clock::now();
  34.  
  35.     std::string code;
  36.  
  37.     ReadFromFile(DIRECTORY + "/" + SOURCE_FILE, code);
  38.  
  39.     for (int i = 0; i < code.size(); i += 1) {
  40.         debug(std::to_string(code[i] == 'e'));
  41.     }
  42.  
  43.     auto finish = std::chrono::high_resolution_clock::now();
  44.     std::chrono::duration<double> elapsed = finish - start;
  45.     debug("Time: " + std::to_string(elapsed.count()) + " seconds.");
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement