Beginner losing his mind trying to understand serialisation in c++, help PLEASE!
Hello all.
Okay i'll try to get straight to the point here and not waste anyones time.
I'm a beginner when it comes to programming, my introduction to the world of programming was with python. About a week ago i decided to start learning c++ as well, as it seems to me learning more than one language would make me a better programmer overall. Now i've been progressing okay with c++, that is up until now.
I want to acheive something similar to pickling and unpickling in python. For example lets say i have a simple class like:
Code:
class Journal{
private:
int ID_number;
string text_entry;
public:
Journal(int x, string y){
ID_number = x;
text_entry = y;
}
void display_data(void){
cout << "\nID: " << ID_number << "\nText: " << text_entry << endl;
};
So obviously an instance of this class would be declared like Journal test(1, "text");
Now all i want to be able to do is store this class instance and it's data into a file in binary form so that i can save the data upon the program being closed, and then retrieve it another time for future use.
Exactly like using the pickle module in python. Now i cannot for the bloody life of me understand why this is not easier to do in c++. What is the standard way people save their data with c++?
Basically i just want to be able to store an object in a file so it is saved to the hard drive, then be able to read it another time and use the data again in future. Exactly like pickling and unpickling objects in python.
This problem has bloody stumped me, and before you guys flame me i definitely have put effort into searching for my own answers but have not been able to work this out on my own.
Would someone here please be able to help me understand how to acheive what i assumed would be a trivial thing to do in c++ but that does not seem to be the case at all, although i'm sure it's not difficult once you understand how to go about acheiving this.
This problem has pretty much created a road block in my c++ learning because i cannot create any real useful programs if i cant even save data and retrieve it another time.
I would be incredibly grateful if someone could spend the time to help me understand and acheive this operation.
I'm starting to feel disillusioned, how can something so trivial and simple in python be so bloody hard to fathom in c++.
I understand everyone has their own projects and work to do so any time spent helping me and my problem here would be *hugely* appreciated and you would not be wasting your time i assure you. I'm beginning to feel quite desperate and starting to despair.
Thankyou