-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateTxt.cpp
More file actions
36 lines (29 loc) · 871 Bytes
/
Copy pathupdateTxt.cpp
File metadata and controls
36 lines (29 loc) · 871 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 <fstream>
#include <string>
#include <cstdio> // for remove(), rename()
int main() {
const char* filename = "slackadmin.txt";
const char* tempFile = "slackadmin_temp.txt";
std::ifstream input(filename);
if (!input.is_open()) {
std::cout << "Could not open input file.\n";
return 1;
}
std::ofstream output(tempFile);
if (!output.is_open()) {
std::cout << "Could not create temp file.\n";
return 1;
}
std::string line;
while (std::getline(input, line)) {
output << line << "\n\n"; // add spacing here
}
input.close();
output.close();
// Replace original file
std::remove(filename);
std::rename(tempFile, filename);
std::cout << "File formatted successfully (in-place).\n";
return 0;
}