#include<iostream>
#include<string>
#include<fstream>
std::fstream DATA; std::ofstream DATA_headers;
class INFO
{
public:
std::string Name, Age, YoE;
};
void File_info(std::string name , std::string Age, std::string YoE)
{
DATA.open("DATA.txt" , std::ios::app );
DATA << name << "\t\t||\t\t" << Age << "\t\t||\t\t" << YoE << "\n";
DATA.close();
}
void Read_info(std::string name, std::string Age, std::string YoE)
{
std::string BOX;
DATA.open("DATA.txt" , std::ios::in );
while (!DATA.eof()) { DATA >> BOX; }
std::cout << BOX;
}
void RESET_info(std::string name, std::string Age, std::string YoE)
{
DATA.open("DATA.txt", std::ios::out);
DATA.close();
DATA.open("DATA.txt", std::ios::app);
DATA << name << "\t\t||\t\t" << Age << "\t\t||\t\t" << YoE << "\n";
}
int main()
{
DATA_headers.open("DATA.txt");
DATA_headers << " Name\t\t - \t\tAge\t\t - \t\tYoE\t\t"; DATA_headers << "\n-----------------------------------------------------\n";
DATA_headers.close();
DATA.open("DATA.txt", std::ios::cur);
char Choose;
int LIMIT = 999; int i = 1;
while (i <= LIMIT)
{
std::cout << "\n\nDo you want to add ? (Y) yes or (N) no , and (R) reset : ";
std::cin >> Choose;
if (Choose == 'Y' || Choose == 'y')
{
INFO Emp_info;
std::cout << "\n\nEnter the emplyee name :- "; std::cin >> Emp_info.Name; std::cout << "\n\nEntered name : " << Emp_info.Name;
std::cout << "\n\nEnter the age :- "; std::cin >> Emp_info.Age; std::cout << "\n\nEntered age : " << Emp_info.Age;
std::cout << "\n\nEnter the Years of Experience :- "; std::cin >> Emp_info.YoE; std::cout << "\n\nEntered YoE : " << Emp_info.YoE;
File_info(Emp_info.Name, Emp_info.Age, Emp_info.YoE); DATA.close();
}
else if (Choose == 'N' || Choose == 'n')
{
std::cout << "Out...";
break;
}
else if (Choose == 'R' || Choose == 'r')
{
INFO Emp_info;
std::cout << "\n\nEnter the emplyee name :- "; std::cin >> Emp_info.Name; std::cout << "\n\n file entered name : " << Emp_info.Name;
std::cout << "\n\nEnter the age :- "; std::cin >> Emp_info.Age; std::cout << "\n\n Entered age : " << Emp_info.Age;
std::cout << "\n\nEnter the Years of Experience :- "; std::cin >> Emp_info.YoE; std::cout << "\n\n Entered YoE : " << Emp_info.YoE;
RESET_info(Emp_info.Name, Emp_info.Age, Emp_info.YoE);
DATA.close();
}
else
{
std::cout << "\n\n **only (Y) or (N) **\n\n ";
}
;
}
}
This code includes an error with std::ios::cur and std::ios::app, what I wanted to do is to type name then years of experience and save it in a file.txt , whenever I wanted to put add a new one insert Y or y and enough is N or n but names i put saved in file and everytime i want to reset names list by using R to reset the saved names .
what should I do or add??