Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <experimental/filesystem>
- #include <iostream>
- #include <string>
- namespace fs = std::experimental::filesystem;
- int main()
- {
- std::string path_to_file;
- std::cout << "Input full path to file: " << std::endl;
- getline(std::cin, path_to_file);
- if (!fs::exists(path_to_file))
- {
- std::cout << "Invalid path!" << std::endl;
- return 0;
- }
- if (fs::is_directory(path_to_file))
- {
- std::cout << "is directory" << std::endl;
- return 0;
- }
- std::ifstream file(path_to_file);
- std::string str;
- std::string file_contents;
- while (std::getline(file, str))
- {
- file_contents += str;
- file_contents += "\n";
- }
- std::cout << file_contents << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement