meysam_online2012
یک شنبه 11 خرداد 1393, 17:13 عصر
سلام به همگی
من با این کد یه سری داده رو از ورودی میگیرم و توی یه فایل ذخیره می کنم
cout<<"information s"<<i<<"\n";
cout<<"enter id:";
cin>>st[i].id;
cout<<"\nenter name:";
cin.ignore();
cin.getline(st[i].name,20);
cout<<"\nenter family:";
cin.getline(st[i].family,20);
cout<<"\nenter fizik:";
cin>>st[i].fizik;
cout<<"\nenter ryazi:";
cin>>st[i].riazi;
cout<<"\nenter shimi:";
cin>>st[i].shimi;
st[i].avg=(st[i].riazi+st[i].fizik+st[i].shimi)/3;
output_file.open("test.txt",ios::ate);
if(!output_file)
{
cerr<<"File can not open."<<endl;
}
else
{
output_file << st[i].id<< " " << st[i].name <<" " <<st[i].family<<" "<<st[i].riazi<<" "<<st[i].fizik<<" "<<st[i].shimi<<" "<<st[i].avg<< endl;
cout<<"succesful";
}
output_file.close();
i++;
که به این ترتیب توی فایل ذخیره میشه
12 12 12 12hasan ali
حالا چطوری باید اینو از فایل بخونم و توی struct ذخیره کنم؟
من با این کد یه سری داده رو از ورودی میگیرم و توی یه فایل ذخیره می کنم
cout<<"information s"<<i<<"\n";
cout<<"enter id:";
cin>>st[i].id;
cout<<"\nenter name:";
cin.ignore();
cin.getline(st[i].name,20);
cout<<"\nenter family:";
cin.getline(st[i].family,20);
cout<<"\nenter fizik:";
cin>>st[i].fizik;
cout<<"\nenter ryazi:";
cin>>st[i].riazi;
cout<<"\nenter shimi:";
cin>>st[i].shimi;
st[i].avg=(st[i].riazi+st[i].fizik+st[i].shimi)/3;
output_file.open("test.txt",ios::ate);
if(!output_file)
{
cerr<<"File can not open."<<endl;
}
else
{
output_file << st[i].id<< " " << st[i].name <<" " <<st[i].family<<" "<<st[i].riazi<<" "<<st[i].fizik<<" "<<st[i].shimi<<" "<<st[i].avg<< endl;
cout<<"succesful";
}
output_file.close();
i++;
که به این ترتیب توی فایل ذخیره میشه
12 12 12 12hasan ali
حالا چطوری باید اینو از فایل بخونم و توی struct ذخیره کنم؟