can someone help with this code

0 Ankit Ojha · August 30, 2015
#include<iostream>
#include<fstream>

using namespace std;

class employee
{
private:
    char name;
    int age;
    string address;
public:
   void getdata();
   void showdata();
};

void employee :: getdata()
    {
      cout<<"\n enter your first name,age,address ";
      cout<<"\n ENTER ctrl+Z to exit"<<endl;
      ofstream empfile;
      empfile.open("empdetails.txt");

      while(cin>>name>>age>>address)
      {
          empfile<<name<<" "<<age<<" "<<address;
      }
    empfile.close();
    }

void employee:: showdata()
{
    ifstream empfile("empdetails.txt");

    char name;
    int age;
    string address;

    while(empfile>>name>>age>>address)
    {
        cout<<"name : "<<name<<"\n"<<"age : "<<age<<"\n"<<"address : "<<address<<"\n"<<endl;
    }

}
can someone help with this code. 

int main()
{
    employee emp1;
    emp1.getdata();
    emp1.showdata();
    return 0;
}


Post a Reply

Replies

Oldest  Newest  Rating
0 Franz Schmidt · August 31, 2015
what exactly is not working or what is this program even supposed to do?
0 Ankit Ojha · September 2, 2015
file is created as empdetails.txt but when i enter the data it does not get saved on the file.
  • 1

C++

107,316 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator