Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <boost/filesystem.hpp>
  5. #include <filesystem>
  6. #include <chrono>
  7. #include <thread>
  8. using namespace std;
  9. using chrono::system_clock;
  10.  
  11. void PrintText(string& line) {
  12. string tline;
  13. ifstream myFile;
  14. myFile.open("C:\\Users\\Toffer\\Desktop\\testfile.txt");
  15. getline(myFile, tline);
  16. if (tline.substr(0, 1) == "@")
  17. if (tline != line) {
  18. line = tline;
  19. cout << line << endl;
  20. }
  21.  
  22. myFile.close();
  23. }
  24.  
  25. //void last_file_change(const filesystem::path& filename) {
  26. // auto file_time = filesystem::last_write_time(filename);
  27. // while (true) {
  28. // if (filesystem::last_write_time(filename) != file_time) {
  29. // file_time = filesystem::last_write_time(filename);
  30. // PrintText(line);
  31. // this_thread::sleep_for(chrono::seconds(3));
  32. // }
  33. // }
  34. //
  35. //}
  36.  
  37. void copy_logfile() {
  38. std::filesystem::copy_file("C:\\Users\\Toffer\\Desktop\\extreme.txt", "C:\\Users\\Toffer\\Desktop\\testfile.txt", std::filesystem::copy_options::overwrite_existing);
  39. }
  40.  
  41. void RefreshText(const filesystem::path& filename) {
  42. string line;
  43. auto file_time = filesystem::last_write_time(filename);
  44. while (true) {
  45. if (filesystem::last_write_time(filename) != file_time) {
  46. file_time = filesystem::last_write_time(filename);
  47. PrintText(line);
  48. //this_thread::sleep_for(chrono::seconds(3));
  49. }
  50. }
  51. }
  52.  
  53. int main() {
  54. copy_logfile();
  55.  
  56. RefreshText("C:\\Users\\Toffer\\Desktop\\extreme.txt");
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement