-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.cpp
More file actions
36 lines (31 loc) · 732 Bytes
/
Copy pathfile.cpp
File metadata and controls
36 lines (31 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include "file.hpp"
using namespace std;
File::File(string&& file): name(file), path(file) {
open(path, ios::ate | ios::in);
}
iostream& File::operator>>(string& content)
{
if (is_open()) close();
open(path, ios::ate | ios::in);
if (!*this) return *this;
content.resize(tellg());
seekg(0);
read(content.data(), content.size());
close();
return *this;
}
iostream& File::operator<<(const string& content)
{
if (!std::filesystem::exists(path.parent_path()))
filesystem::create_directories(path.parent_path());
if (is_open()) close();
open(path, ios::trunc | ios::out);
write(content.data(), content.size());
close();
return *this;
}
const char* File::getName() const
{
return path.c_str();
}