Skip to content

Commit 95be763

Browse files
committed
file_io.cpp: move most to lkmc
1 parent 7b5ee8a commit 95be763

File tree

1 file changed

+1
-65
lines changed

1 file changed

+1
-65
lines changed

cpp/file_io.cpp

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void ios_read_fail(std::string path) {
2020

2121
/**
2222
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
2324
*/
2425
void read_file(std::ifstream &ifs, std::string &data_read) {
2526
ifs.seekg(0, std::ios::end);
@@ -45,24 +46,6 @@ int main() {
4546
}
4647
}
4748

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-
6649
/*
6750
# Copy file to another
6851
@@ -104,53 +87,6 @@ int main() {
10487
}
10588
}
10689

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-
15490
/*
15591
# binary io
15692

0 commit comments

Comments
 (0)