struct data {
string name;
string last_name;
string description;
string key_words;
string title;
int age;
};
data data1;
void display_file(){
ifstream binaryFile;
int size = 0;
binaryFile.open("data.dat",ios::in | ios::binary);
binaryFile.seekg(0,ios::end);
size = (int)binaryFile.tellg();
binaryFile.seekg(0,ios::beg);
while(binaryFile.tellg() < size){
binaryFile.read((char*) &dane1, sizeof(dane));
cout << name << last_name << description << key_words << title << age;
}
// save to file
ofstream plik;
plik.open("data.dat",ios::out | ios::binary | ios::app);
if(plik.is_open()){
plik.write((const char *) &data1, sizeof(data));
plik.close();
}
Hello in other method i had get_data to input all this values to binary file and in this method I want to read from binary file. The problem is that when I try to run this method program shows me only integers and in place where string value supposed to be i get garbage data. I know this method can read char array[] strings, but is this possible to read std::string in c++?