GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C++

 Print  |  
Question:  Write Object into a File

Answer: How will you write object into file using file concepts in C++?


February 02, 2009 20:13:28 #2
 sim_sam   Member Since: February 2009    Total Comments: 3 

RE: Write Object into a File
 
A function in the class definition can be included which writes to the standard file stream and takes the name of target file as a parameter. Function prototype will be like this:

WriteObjectToFile (const char* fileName)
{
ofstream fout(fileName);
fout<< myVar1<<myVar2<<endl;
fout.close();
}

     

 

Back To Question