Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Files.h"
- namespace ulib
- {
- namespace files {
- // ReadFile
- const file_content ReadFile(const file_path& to_read)
- {
- std::ifstream file_stream(to_read);
- std::string line_data;
- std::vector<std::string> file_data;
- if (file_stream.is_open())
- {
- while (std::getline(file_stream, line_data))
- file_data.push_back(line_data);
- return file_data;
- }
- return { "\0" };
- }
- // WriteFile
- const bool WriteFile(const file_path& to_write, file_content& data)
- {
- std::ofstream file_stream(to_write);
- if (file_stream.is_open())
- {
- for (auto& line_in : data)
- file_stream << line_in << "\n";
- return true;
- }
- return false;
- }
- // CreateFile
- const bool CreateFile(const file_path& to_create)
- {
- if (!CheckFile(to_create))
- outfile file_stream(to_create, std::ios::app);
- if (CheckFile(to_create))
- return true;
- return false;
- }
- // DeleteFile
- const bool DeleteFile(const file_path& to_delete)
- {
- file file_stream(to_delete);
- if (file_stream.is_open())
- {
- file_stream.close();
- std::remove(to_delete.c_str());
- return true;
- }
- return false;
- }
- // CheckFile
- const bool CheckFile(const file_path& to_check)
- {
- std::fstream file_stream(to_check);
- if (file_stream.is_open())
- return true;
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement