Do trước đây mình bỏ qua phần File nên giờ gặp 1 bài toán khá là bế tắc.Chạy mà lỗi hoài.Khi mình nhập vài SV và xuất Sv ra thì no1 chỉ xuất 1 sv mà còn xuất lỗi nữa.Trong khi nó ghi trong file thì bình thường.Ai chỉ ra lỗi dùm mình với.Mình cảm ơn. 
#include <iostream>
#include <conio.h>
#include <string>
#include <stdlib.h>
#include <fstream>
using namespace std;
struct SinhVien
{
string ID;
string FirstName;
string LastName;
double Math;
double Physics;
double English;
double Avg;
};
void NhapSV(SinhVien &sv)
{
cin.ignore();
cout << "Ma so sinh vien : ";
getline(cin,sv.ID);
cout << "Nhap ten : ";
getline(cin,sv.LastName);
cout << "Nhap ho : ";
getline(cin,sv.FirstName);
cout << "Diem toan : ";
cin >> sv.Math;
cout << "Diem ly : ";
cin >> sv.Physics;
cout << "Diem tieng Anh : ";
cin >> sv.English;
}
void NhapDanhSach(SinhVien ds[],int &n)
{
cout << "So luong sinh vien can nhap : ";
cin >> n;
for(int i = 0 ; i < n ; i++)
{
cout << "Nhap thong tin sinh vien thu " << i + 1 << endl;
NhapSV(ds[i]);
}
ofstream input("Sinh Vien.txt",ios::out);
input << n << endl;
for(int i = 0 ; i < n ; i++)
{
input << i + 1 << " " << ds[i].ID << " " << ds[i].LastName << " " << ds[i].FirstName << endl;
input << "Diem toan : " << ds[i].Math << endl;
input << "Diem Van : " << ds[i].Physics << endl;
input << "Diem Anh : " << ds[i].English << endl;
}
input.close();
}
void DocFile(char TenFile[],SinhVien ds[],int &n)
{
ifstream output(TenFile,ios::in);
output >> n;
for(int i = 0 ; i < n ; i++)
{
output >> ds[i].ID ;
output >> ds[i].LastName;
output >> ds[i].FirstName;
output >> ds[i].Math;
output >> ds[i].Physics;
output >> ds[i].English;
}
output.close();
}
void InSV(SinhVien sv)
{
cout << " " << sv.ID << " " << sv.LastName << " " << sv.FirstName << endl;
}
void XuatDanhSach(SinhVien ds[],int n)
{
for(int i = 0 ; i < n ; i++)
{
cout << i + 1 << " " << ds[i].ID << " " << ds[i].LastName << " " << ds[i].FirstName << endl;
}
}
int main()
{
SinhVien ds[100];
int n;
NhapDanhSach(ds,n);
char TenFile[] = "Sinh Vien.txt";
DocFile(TenFile,ds,n);
//system("cls");
XuatDanhSach(ds,n);
getch();
return 0;
}


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?