At the moment I have such a problem, I want to write contents of struct to a file, got read some topics covering this in the internet(google) but still it makes some troubles.
What I'm doing:
Implementing my struct:
struct MyStruct
{
int testint;
float testfloat;
};
Adding a child one,assigning values:
MyStruct myStruct;
myStruct.testint=123;
myStruct.testfloat=1.23f;
Opening a filestream,file,writing,closing:
std::ofstream writemystruct;
writemystruct.open("testfile.txt");
writemystruct.write((char*)&myStruct,sizeof(myStruct));
writemystruct.close();
But what I get in file is not what I want. Some variety of symbols.
So I am asking for assistance in this, how to write contents of the struct in file?
Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.