-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddingPost.h
More file actions
93 lines (80 loc) · 2.11 KB
/
AddingPost.h
File metadata and controls
93 lines (80 loc) · 2.11 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
#define RESET "\033[0m"
#define RED "\033[1;31m"
#define GREEN "\033[1;32m"
#define YELLOW "\033[1;33m"
#define BLUE "\033[1;34m"
#define MAGENTA "\033[1;35m"
#define CYAN "\033[1;36m"
#define piss pair<int, pair<string, string>> // piqa stands for pair of (integer question answer)
#define ff first
#define ss second
class POST
{
public:
vector<piss> arr;
int i = -1;
void ReadFeed(void)
{
int num;
string Number;
string Question;
string Answer = "";
// string temp = "";
ifstream read;
read.open("feed.txt");
while (!(getline(read, Number)).eof())
{
Answer = "";
try
{
num = stoi(Number);
}
catch (const invalid_argument &e)
{
cerr << "Invalid argument: " << e.what() << endl;
continue;
}
getline(read, Question);
getline(read, Answer);
arr.push_back(make_pair(num, make_pair(Question, Answer)));
}
read.close();
}
string addingPost(void)
{
string Question, Answer;
int ID = arr.size();
ID++;
cout << YELLOW << "Type your Question:" << RESET << endl;
cin.ignore();
getline(cin, Question);
cout << YELLOW << "Type your Answer: (If Not want to write the answer just Press Enter) " << RESET << endl;
getline(cin, Answer);
arr.push_back(make_pair(ID, make_pair(Question, Answer)));
reWriteToFile();
if (Answer.length() > 0)
return to_string(ID);
return "";
}
void reWriteToFile(void)
{
ofstream write;
string str;
write.open("feed.txt"); // change the file name
for (auto i : arr)
{
write << i.ff << "\n";
write << i.ss.ff << "\n";
if ((i.ss.ss).length() != 0)
{
write << i.ss.ss << "\n";
}
}
write.close();
}
};