I am using ofstream
to write an object of contact manager into the text file using dev C++. My objective is to save the object into the text file so that the Name and Phone can be read from the text file too. Following is my simple code:
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
class phone
{
int phone;
string name;
public:void get()
{
cin>>phone;
cin>>name;
}
public:void show()
{
cout<<phone<<"-"<<name;
}
};
int main () {
phone p;
p.get();
p.show();
ofstream outfile("12.txt"); // Open the file in output mode
outfile.write((char*)&p, sizeof(p)); // Write the object into the file
return 0;
}
But when I open the Text file, it shows some chinese Characters. Any help on how to fix it?