本文发表在 rolia.net 枫下论坛Do you have somebody tell me where I make mistake?
Car *temp = new Car[x];
for (int i=0;i<x; i++)
{ cout<<"read file";
file2.read((char *)&temp, sizeof(Car)*x);
cout<<(i+1)<<"Car="<<temp;
}
-----------------------------------------------------------------------------
void main()
{
int x;
cout<<"\n Number of Cars => ";
cin>>x;
Car *pcars = new Car[x];
if (!pcars)
{
cout<<"\nMemory Allocation Error!";
exit(1);
}
for (int i=0;i<x; i++)
cin>>pcars[i];
ofstream file1("CARS.DAT", ios::out);
if (!file1)
{
cerr<<"Error in opening file for output!";
exit(1);
}
file1.write((char *)pcars, sizeof(Car)*x);
file1.close();
ifstream file2("CARS.DAT");
//ifstream file2("CARS.DAT", ios::in);
if (!file2)
{
cerr<<"Error in opening file for input!";
exit(1);
}
//Car temp;
Car *temp = new Car[x];
for (int i=0;i<x; i++)
{ cout<<"read file";
file2.read((char *)&temp, sizeof(Car)*x);
cout<<(i+1)<<"Car="<<temp;
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
Car *temp = new Car[x];
for (int i=0;i<x; i++)
{ cout<<"read file";
file2.read((char *)&temp, sizeof(Car)*x);
cout<<(i+1)<<"Car="<<temp;
}
-----------------------------------------------------------------------------
void main()
{
int x;
cout<<"\n Number of Cars => ";
cin>>x;
Car *pcars = new Car[x];
if (!pcars)
{
cout<<"\nMemory Allocation Error!";
exit(1);
}
for (int i=0;i<x; i++)
cin>>pcars[i];
ofstream file1("CARS.DAT", ios::out);
if (!file1)
{
cerr<<"Error in opening file for output!";
exit(1);
}
file1.write((char *)pcars, sizeof(Car)*x);
file1.close();
ifstream file2("CARS.DAT");
//ifstream file2("CARS.DAT", ios::in);
if (!file2)
{
cerr<<"Error in opening file for input!";
exit(1);
}
//Car temp;
Car *temp = new Car[x];
for (int i=0;i<x; i++)
{ cout<<"read file";
file2.read((char *)&temp, sizeof(Car)*x);
cout<<(i+1)<<"Car="<<temp;
}更多精彩文章及讨论,请光临枫下论坛 rolia.net