Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Exception : public std::exception
- {
- public:
- enum class State { FILE_DOES_NOT_EXISTS = 1, FILE_IS_NOT_OPEN = 2 };
- explicit Exception(State state) : state(state) {}
- const char* what() const noexcept override { return state_to_string(); }
- private:
- const char* state_to_string() const
- {
- switch (state)
- {
- case State::FILE_DOES_NOT_EXISTS:
- return "File does not exists";
- case State::FILE_IS_NOT_OPEN:
- return "File is not open";
- }
- }
- private:
- State state;
- };
- list read_file(const fs::path& file_path)
- {
- if(!fs::exists(file_path))
- throw Exception{Exception::State::FILE_DOES_NOT_EXISTS};
- std::ifstream infile{file_path.string()};
- if(!infile.is_open())
- throw Exception{Exception::State::FILE_IS_NOT_OPEN};
- list data{};
- std::string number{""};
- while(std::getline(infile, number, ','))
- data.push_back(std::stoi(number));
- return data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement