forked from Ak0s/zerda-exam-cpp-orientation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.cpp
More file actions
47 lines (41 loc) · 1.03 KB
/
File.cpp
File metadata and controls
47 lines (41 loc) · 1.03 KB
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
37
38
39
40
41
42
43
44
45
46
#include "File.hpp"
File::File() : content("") {}
std::string File::read_in_file(std::string input_file_name) {
std::ifstream myfile;
myfile.open(input_file_name);
std::string buffer;
if (!myfile.is_open()) {
std::cout << "Error: your file is not open!\n";
} else {
while (getline(myfile, buffer)) {
content += buffer + "\n";
}
myfile.close();
}
return content;
}
void File::write_to_file(std::string output_file_name, std::string content) {
std::ofstream myfile;
myfile.open (output_file_name);
if (!myfile.is_open()) {
std::cout << "Error: the file is not open\n";
} else {
myfile << content;
myfile.close();
}
}
void File::print_content_to_screen(std::string input_file_name) {
std::ifstream myfile;
myfile.open(input_file_name);
if (!myfile.is_open()) {
std::cout << "Error: the file is not open\n";
} else {
while (getline(myfile, content)) {
std::cout << content << std::endl;
}
myfile.close();
}
}
std::string File::get_content() {
return content;
}