Lỗi đọc file C++
Nó bị như vầy giờ phải làm sao ạ ?
Code
#include “iostream”
#include “string”
#include “conio.h”
#include “windows.h”
#include “fstream”
#include “sstream”
using namespace std;
class SinhVien
{
private:
string name;
string address;
int old;
int Toan, Ly, Hoa;
public:
void setTT()
{
cin.ignore();
cout<<“What’s your name?”<<endl; getline(cin,this->name);
cout<<“How old are you?”<<endl; cin>>this->old;
cin.ignore();
cout<<“Where are you?”<<endl; getline(cin,this->address);
cout<<“What’s your Math scores?”<<endl; cin>> Toan;
cout<<“What’s your Physical scores?”<<endl; cin>>Ly;
cout<<“What’s your Chemistry scores?”<<endl; cin>>Hoa;
}
void ghi(ofstream &ofs)
{
ofs<<name<<" “<<old<<” “<<address<<”
"<<Toan<<" “<<Ly<<” "<<Hoa<<endl;
}
void getTT()
{
cout<<"Name : "<name<<endl;
cout<<"Tuoi : "<old<<endl;
cout<<"Dia chi : "<address<<endl;
cout<<"Toan : “<Toan<<” Ly : “<Ly<<” Hoa : "<Hoa<<endl;
}
float DiemTB()
{
return (float)((Toan+Ly+Hoa)/3);
}
};
class QuanLySinhVien
{
private:
SinhVien *sinhvien;
int sosv;
public:
~QuanLySinhVien()
{
delete sinhvien;
}
void Write()
{
ofstream ofs(“FILE.txt”,ios::out|ios::app);
ofs.clear();
cout<<“Nhap so sinh vien”<<endl; cin>>this->sosv;
sinhvien = new SinhVien[sosv];
for(int i=0;i<sosv;i++)
{
system("cls");
cout<<"Nhap Thong Tin Sinh Vien thu "<<i+1<<endl;
sinhvien[i].setTT();
sinhvien[i].ghi(ofs);
}
ofs.close();
}
void Read()
{
ifstream ifs("FILE.txt",ios::in);
char data[100];
if(!ifs.is_open())
{
cout<<"Khong mo duoc FILE "<<endl;
}else
{
while(!ifs.eof()&&ifs.good())
{
if(ifs.eof())
{
ifs.close();
}
else
{ifs.getline(data,100);
cout<<data<<endl;
}
}
}
}
void xetTN()
{
int svTN = 0;
for(int i= 0; i<sosv;i++)
{
if(sinhvien[i].DiemTB() >= 5.0)
{
svTN ++;
}
}
cout<<"So sv tot nghiep la : "<<svTN<<endl;
cout<<"So sv truot TN la : "<< sosv-svTN<<endl;
}
};
int main()
{
QuanLySinhVien QLSV;
// QLSV.Write();
system(“cls”);
QLSV.Read();
return 0;
}
Hi Nguyen Trong Dung,
Bị như vậy bạn phải cung cấp đầy đủ code cho mọi người dễ dàng chạy code và tìm bug nhé.
~fly away~