using namespace std;
class Motherboards
{
char Board_Manufacturer_Name[50];
char Socket_Type[50];
char Chipset_Type[50];
char Board_Name[50];
char Feature1[500];
char Feature2[500];
char Feature3[500];
float Price;
public:
void getdata();
void displaydata();
};
void Motherboards::getdata()
{
cout << " Enter Manufacturer Name :\n";
cin.getline(Board_Manufacturer_Name, 50);
cout << "\n Enter the Socket type :\n";
cin.getline(Socket_Type, 50);
cout << "\n Enter the Chipset Type :\n";
cin.getline(Chipset_Type, 50);
cout << "\n Enter the Board Name :\n";
cin.getline(Board_Name, 50);
cout << "\n Enter 3 main features for this Board :\n";
cout << "\n1.) ";
cin.getline(Feature1, 500);
cout << "\n2.) ";
cin.getline(Feature2, 500);
cout << "\n3.) ";
cin.getline(Feature3, 500);
cout << "Price :\n";
cin >> Price;
cout << "\n";
}
void Motherboards::displaydata()
{
cout << " Manufacturer : " << Board_Manufacturer_Name << endl;
cout << " Socket : " << Socket_Type << endl;
cout << " Chipset : " << Chipset_Type << endl;
cout << " Board Name : " << Board_Name << endl;
cout << " Features :\n" << "1.) " << Feature1 << endl
<< "2.) " << Feature2 << endl
<< "3.) " << Feature3 << endl;
cout << " Price :\n" << Price;
cout << "\n";
}
int main()
{
int x;
system("cls");
Motherboards M;
fstream Infile;
Infile.open("MotherboardList.dat", ios::in | ios::out | ios::app);
if (!Infile)
{
cerr << "Error :";
}
cout << "Enter the details of the motherboard that you want to add :\n";
M.getdata();
Infile.write((char*)&M, sizeof(Motherboards));
cout << "Do youwanna confirm ?";
M.displaydata();
cin >> x;
cout << "Written :\n";
Infile.read((char*)&M, sizeof(Motherboards));
M.displaydata();
Infile.close();
return 0;
}
First of all i want to know why my data is being written in some random language maybe Chinese idk but also what to change to actually write the data properly.
Aucun commentaire:
Enregistrer un commentaire