Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- class emp{
- string empid;
- string name;
- public:
- emp()
- {
- empid = "0";
- name = "abc";
- }
- void accept()
- {
- cout<< "Enter employee details" << endl;
- cout << "Enter employee id: " << endl;
- cin >> empid;
- cout << "Enter employee name: " << endl;
- cin >> name;
- }
- void display()
- {
- cout << "Employee ID: " << empid << endl;
- cout << "Employee name: " << name << endl;
- }
- };
- int main()
- {
- emp e1,e2;
- fstream file;
- int ch = 10;
- while(ch != 0){
- cout << "Enter your choices: " << endl;
- cout << "1: Write in file" << endl;
- cout << "2: Read from file" << endl;
- cout << "0: Exit" << endl;
- cin >> ch;
- switch(ch){
- case 1:
- file.open("/workspaces/codespaces-blank/DATA");
- e1.accept();
- file.write((char*)&e1,sizeof(e1));
- file.close();
- break;
- case 2:
- file.open("/workspaces/codespaces-blank/DATA");
- file.read((char*)&e1,sizeof(e1));
- e1.display();
- file.close();
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement