|
-
February 11th, 2009, 07:34 AM
#1
Writing structures of vectors / std::string into binary file
Hi,
I am using the following structures
struct KeyValPair
{
std::string Key;
std::string Value
};
struct Properties
{
std::string PropertyName;
vector <KeyValPair > PropVal;
};
struct MainComponent
{
std::string MainName;
vector < Properties > Properties;
};
Now in my mail program, I have defined
vector < MainComponent > objComponent;
and I am storing say 10 components values inside this one.
I want these values of the 10 components the next time I execute the program. So the only option I have is to write to file as binary data right ??
Can someone show me how this can be achieved ?
I tried the FILE *fp; thingy and the fwrite and fread
E.g.
FILE*fp;
fp = fopen("c:\\Component.dat","wb");
fwrite(&objComponent,sizeof(objComponent),2,fp);
But i am getting errors. I dont know how to fill parameters for the fwrite since it contains vectors which can be variable.
I am forced to use only standard C++ libraries as this is part of a helper class for a bigger program.
Please do help me.... I am also googling since morning but without much success..
thanks in anticipation.
Also i would be delighted if someone would post with code examples to my program.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|