Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- bool CheckExtension(const std::string& path_to_file) {
- const std::string extension = "txt";
- if (path_to_file.substr(path_to_file.length() - 3) == extension)
- {
- return true;
- }
- else {
- std::cout << "Wrong file's extension!\n";
- return false;
- }
- }
- bool CheckPermissionForReading(const std::string& path_to_file)
- {
- std::ifstream file_out(path_to_file);
- if (file_out.is_open())
- {
- file_out.close();
- return true;
- }
- else
- {
- std::cout << "File can not be opened!\n";
- return false;
- }
- }
- bool CheckPermissionForWriting(const std::string& path_to_file)
- {
- std::ofstream file_out(path_to_file);
- if (file_in.is_open())
- {
- file_in.close();
- return true;
- }
- else
- {
- std::cout << "Can not write in this file!\n";
- return false;
- }
- }
- const std::string inputPathToFileForWriting()
- {
- std::string path_to_file;
- do
- {
- std::cout << "Enter path to file: \n";
- getline(std::cin, path_to_file);
- } while (!CheckExtension(path_to_file) || !CheckPermissionForWriting(path_to_file));
- return path_to_file;
- }
- const std::string inputPathToFileForReading()
- {
- std::string path_to_file;
- do
- {
- std::cout << "Enter path to file: \n";
- getline(std::cin, path_to_file);
- } while (!CheckExtension(path_to_file) || !CheckPermissionForReading(path_to_file));
- return path_to_file;
- }
- const std::string inputPathToFile()
- {
- std::string path_to_file;
- do
- {
- std::cout << "Enter path to file: \n";
- getline(std::cin, path_to_file);
- } while (!CheckExtension(path_to_file) || !CheckPermissionForReading(path_to_file) || !CheckPermissionForWriting(path_to_file));
- return path_to_file;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement