@@ -20,6 +20,7 @@ void ios_read_fail(std::string path) {
20
20
21
21
/* *
22
22
Read entire file into a string at once.
23
+ https://stackoverflow.com/questions/116038/what-is-the-best-way-to-read-an-entire-file-into-a-stdstring-in-c
23
24
*/
24
25
void read_file (std::ifstream &ifs, std::string &data_read) {
25
26
ifs.seekg (0 , std::ios::end);
@@ -45,24 +46,6 @@ int main() {
45
46
}
46
47
}
47
48
48
- /*
49
- # Read entire file at once
50
-
51
- http://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring
52
-
53
- Best way seems to be to get file size, allocate, and read manually.
54
- */
55
- {
56
- std::ifstream ifs (path);
57
- if (ifs) {
58
- std::string data_read;
59
- read_file (ifs, data_read);
60
- assert (data_read == data);
61
- } else {
62
- ios_read_fail (path);
63
- }
64
- }
65
-
66
49
/*
67
50
# Copy file to another
68
51
@@ -104,53 +87,6 @@ int main() {
104
87
}
105
88
}
106
89
107
- /*
108
- # Compare two files larger than memory.
109
-
110
- TODO is there an easier way than reading each?
111
- */
112
- {
113
- }
114
-
115
- // # Append to file
116
- {
117
- std::ofstream ofs (path);
118
-
119
- if (ofs) {
120
- ofs << data;
121
- ofs.close ();
122
- } else {
123
- ios_write_fail (path);
124
- }
125
-
126
- /*
127
- # open
128
-
129
- # Reopen
130
-
131
- Can be used to reopen ofstream with new properties.
132
-
133
- Also consider clearing error flags if there can be any.
134
- */
135
- // ofs.clear()
136
- ofs.open (path, std::ios::app);
137
- if (ofs) {
138
- ofs << data;
139
- ofs.close ();
140
- } else {
141
- ios_write_fail (path);
142
- }
143
-
144
- std::ifstream ifs (path);
145
- if (ifs) {
146
- std::string data_read;
147
- read_file (ifs, data_read);
148
- assert (data_read == data + data);
149
- } else {
150
- ios_read_fail (path);
151
- }
152
- }
153
-
154
90
/*
155
91
# binary io
156
92
0 commit comments