-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_task.h
More file actions
59 lines (54 loc) · 1.66 KB
/
Copy pathedit_task.h
File metadata and controls
59 lines (54 loc) · 1.66 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
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include<string.h>
#include <ctime>
using namespace std;
class EditTask{
public:
void edit();
private:
bool editTaskByID(int taskID);
};
void EditTask::edit() {
int taskID;
cout << "Enter Task ID to edit: ";
cin >> taskID;
if (editTaskByID(taskID)) {
cout << "Task with ID " << taskID << " edited successfully.\n";
} else {
cout << "Task with ID " << taskID << " not found.\n";
}
}
bool EditTask::editTaskByID(int taskID) {
ifstream fin;
fin.open("Task.txt");
ofstream temp;
temp.open("temp.txt");
string line;
bool found = false;
time_t now = time(0);
while (getline(fin, line)) {
if (line.find("Task ID:" + to_string(taskID)) != string::npos) {
found = true;
string content, expire_date;
string timestamp = ctime(&now);
timestamp.pop_back();
cin.ignore(); // Clear the input buffer
cout << "Enter task content: ";
getline(cin, content);
cout << "Enter task expire date (YYYY-MM-DD): ";
getline(cin, expire_date);
temp <<"Task ID:"<<taskID<<" "<< content << " "; // Write content to the file
temp << "current date at the creation: " << timestamp << " "; // Write current timestamp to the file
temp << "task expiring date: "<< expire_date << "\n"; // Write expire date to the file
std::cout << "Task modified!"<< std::endl;
} else {
temp << line << endl;
}
}
temp.close();
fin.close();
remove("Task.txt");
rename("temp.txt", "Task.txt");
return found;
}