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