I want to use the data members to store the info on the file and then read and display them through these two member functions in the class but i can't think of syntax. i made global variables but didn't use the data members in the class. i stored and read data by global variables but couldn't do it by data members of the class.


/* Making Global Pointer Variables to use anywhere in the program*/
             const char* ID =       "VUID          = "mc123456789";
             const char* camID =    "Campus ID     = "PMMK08"; 
             const char* stdntnme = "Name          = "xxxx xxxx xxxx";
             const char* Fthrnme =  "Father's Name = "xxxx xxxx xxxx";
ofstream re;
class studentinfo
      private:/*Creating Private Data Members */
              char* VUID;
              char* campusID;
              char* Studentname;
              char* Fathername;

             void Storefile();/* Function to Store Data in the File*/
             char Display();/*Function to Read and then Display Data from the File*/
             studentinfo(char*, char*, char*, char*);/*Constructor to initialize Data Members*/
/* Constructor Defined Here*/
studentinfo::studentinfo(char* VUID, char* campusID, char* Studentname, char* Fathername)
cout<<"Parameterized Contructor is Called"<<endl<<endl;
/*Destructor Defined Here*/
cout<<"Destructor Called for destruction of the object"<<endl;
/*Function to Store Data in the File Defined here*/
void studentinfo::Storefile()

              if(!re)/*Error Checking Mechanism*/
                         cout<<"Error Reading File"<<endl;
              re<<ID<<endl<<camID<<endl<<stdntnme<<endl<<Fthrnme<<endl;/*Using Global Pointer Variables to Store data in the File*/
              cout<<"All the Data Members are Stored in a File"<<endl<<endl;
/*Function to Read and then Display the data in the File is definde here */              
char studentinfo::Display()
              char output[100];/*Array to store and display the data*/
              ifstream reh;
                         cout<<"Error Reading File"<<endl;

              cout<<"Following is My Data"<<endl<<endl;
              reh.getline(output, 100, '\n');/*Reading the data and storing it in the 'output' array line by line*/



/*Main Function starting here*/                  
      studentinfo s1("mc123456789", "PMMk08", "xxx xxxx xxxx","xxxx xxxx xxxxx");/*Object Created and Initialized by constructor calling*/
      s1.Storefile();/*Function Call*/
      s1.Display();/*Function Call*/

This article has been dead for over six months. Start a new discussion instead.