Hi all,
I am trying to write a general function that when called is able to write the value of all the member variables of an object passed to it. This function is part of a class.
The class objects that I want to write out each have a member called "key" which stores the names of the other variables in the class in a vector of strings.
I'm basically trying to write the following type of function to write out the contents of the member variables:
void writeObject2File( string objectName, string outputFilename )
{
ofstream datafile;
datafile.open( filename.c_str() );
for ( unsigned int i=0; i<key.size(); i++ )
datafile << objectName.c_str()->key.at( i ).c_str();
}
This doesn't work, which I guess is probably quite a novice error. The issue I'm having right now is with the following bit:
objectName.c_str()->key.at( i ).c_str();
How do I use the objectName string which defines the name of the object to access the specific object? And how do I then use the variable names stored in the vector key to access their values and subsequently print them to the datafile?
I would really appreciate it if someone can help me sort this out.
Thanks in advance,
Kartik