Advertisement
Guest User

Untitled

a guest
May 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <fstream>
  2. #include <experimental/filesystem>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. namespace fs = std::experimental::filesystem;
  7.  
  8. int main()
  9. {
  10.     std::string path_to_file;
  11.     std::cout << "Input full path to file: " << std::endl;
  12.     getline(std::cin, path_to_file);
  13.  
  14.     if (!fs::exists(path_to_file))
  15.     {
  16.         std::cout << "Invalid path!" << std::endl;
  17.         return 0;
  18.     }
  19.     if (fs::is_directory(path_to_file))
  20.     {
  21.         std::cout << "is directory" << std::endl;
  22.         return 0;
  23.     }
  24.     std::ifstream file(path_to_file);
  25.     std::string str;
  26.     std::string file_contents;
  27.     while (std::getline(file, str))
  28.     {
  29.         file_contents += str;
  30.         file_contents += "\n";
  31.     }
  32.     std::cout << file_contents << std::endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement