Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Customer{
- // data members --- by default private
- int id ;
- char name[20];
- // funtcion
- public :
- void setId(){
- cout <<"Enter ID : ";
- cin >> id;
- }
- int getId(){
- return id;
- }
- void setName(){
- cout << "Enter name : ";
- cin >> name ;
- }
- char* getName(){
- return name;
- }
- };
- int main(){
- ofstream out("data.txt" , ios::out | ios::app );
- Customer c1 ;
- char ch = 'Y';
- do{
- c1.setId();
- c1.setName();
- out.write( (char*)&c1 , sizeof(c1));
- cout <<"if you want to enter another data \t press Y/N \n";
- cin >> ch ;
- }while( ch=='Y');
- out.close();
- ifstream in ("data.txt" , ios::in);
- if(in.is_open()){
- cout << "Id\tName\n";
- while(!in.eof()){
- in.read( (char *) &c1 , sizeof(c1));
- if(!in.eof())
- cout << c1.getId() << '\t' << c1.getName() << "\n" ;
- }
- }else cout <<"Can't open the file \n";
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement