I'm studying c++. there is a source code of refecterging_44 class.
#include <iostream>
#include <string>
using namespace std;
class refecterging_44 {
public:
refecterging_44() {
m_1 = "sdgsdg";
m_2 = 100;
m_3 = 123123;
num = sizeof(refecterging_44);
ptr = &m_1[0];
}
refecterging_44(string name, int score, int id, size_t num, char* ptr) {
refecterging_44::m_1 = m_1;
refecterging_44::m_2 = m_2;
refecterging_44::m_3 = m_3;
refecterging_44::num = num;
refecterging_44::ptr = ptr;
}
void write(ostream& os) {
os.write((char*)this, sizeof(refecterging_44));
os.write((char*)ptr, num);
}
void read(istream& is) {
is.read((char*)this, sizeof(refecterging_44));
is.read((char*)ptr, num);
}
private:
string m_1;
int m_2;
int m_3;
size_t num;
char* ptr;
};
'm_1', 'm_2', 'm_3' are just samples of object about each data value. and 'num' is bytes of memory were Assigned, 'ptr' is address of beginning memory
if I saved the data in txt or other file with write(), how I read this data in the file? can't read the file with my read() function.
When Need additional information, I will comment. Sorry about my silly question. Please understand my low level explanation, because my knowledge is low level... :(