-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdone.cpp
66 lines (59 loc) · 1.26 KB
/
done.cpp
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
60
61
62
63
64
65
66
//done : function to complete the todo
void done(int num)
{
vector<string>v;
int count=0;
char line[50];
ifstream fin;
fin.open("todo.txt");
while( fin.getline(line,50))
{
count++;
}
fin.close();
if(num<=count && num>=1)
{
fin.open("todo.txt");
int i=0;
while(i<count)
{
fin.getline(line,50);
v.push_back(line);
i++;
}
fin.close();
int diff=count-num;
vector<string>::iterator itr;
itr=v.begin();
itr+=diff;
ifstream fr;
fr.open("done.txt",ios::in);
char ch[50];
int k=0;
while(fr.getline(ch,50))
{
k++;
}
fr.close();
ofstream f1;
f1.open("done.txt",ios::out|ios::app);
if(k!=0)
f1<<"\n";
f1<<*itr;
f1.close();
v.erase(itr);
ofstream fout;
fout.open("todo.txt",ios::out);
for(auto i=v.begin();i!=v.end();i++)
{
fout<<*i;
if((i+1)!=v.end())
fout<<"\n";
}
fout.close();
cout<<"Marked todo #"<<num<<" as done.";
}
else{
cout<<"Error: todo #"<<num<<" does not exist.";
}
}