Hi!
Using string, ifstream and ofstream object. Compiling - ok, but give a run-time error after printing Name in ReadData() function.
My Person class include only one string member "name" and function "Name()" which return string object "this->name". And constructor with string parameter of course...
#include <iostream>
#include <fstream>
#include "Person.h"
using namespace std;
void ReadData(string path)
{
ifstream rFile;
Person temp;
rFile.open(path, ios::in);
rFile.read((char*)&temp, sizeof(temp));
cout << temp.Name();
rFile.close();
}
void WriteData(string path)
{
ofstream wFile(path, ios::out);
Person man("My Name");
cout << man.Name();
wFile.write((char*)&man, sizeof(man));
wFile.close();
}
can someone give a tips for this?
Thanks