-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedit.cpp
More file actions
42 lines (28 loc) · 978 Bytes
/
edit.cpp
File metadata and controls
42 lines (28 loc) · 978 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
37
38
39
40
41
42
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
int main()
{
std::string filename,content;
cout << "Enter the name of the file to edit: ";
getline(cin,filename);
// Open the file for reading and writing
fstream editFile(filename.c_str(), ios::app);
if (editFile.is_open()) {
// Get the content to write to the file
cout << "Enter the new content for " << filename << ":" << endl;
getline(cin, content);
// Overwrite the old content with the new content
editFile << "\n";
editFile << content;
// Close the file
editFile.close();
cout << "File saved" << endl;
}
else {
// File not found
cout << "File not found" << endl;
}
return 0;
}