我有以下代码,我想构建一个对象。我怎么能做到?有任何想法吗?该类的类型为 {sting,int,int}。
代码:
void StudentRepository::loadStudents(){
ifstream fl;
fl.open("studs.txt");
Student A();
if(fl.is_open()){
while(!(fl.eof())){
getline(???); //i dont knwo houw coudl i limit what i want were...
}
}
else{
cout<<"~~~ File couldn't be open! ~~~"<<endl;
}
}
保存到文件功能:
void StudentRepository::saveStudents(){
ofstream fl;
fl.open("studs.txt");
if(fl.is_open()){
for(unsigned i=0; i<students.size(); i++){
fl<<students[i].getName();
fl<<",";
fl<<students[i].getID();
fl<<",";
fl<<students[i].getGroup();
fl<<","<<endl;
}
}
else{
cout<<"~~~ File couldn't be open! ~~~"<<endl;
}
我试图实施一些限制,但这不起作用......我该怎么做?
最初我只是将对象写入文件,但很难将它们恢复到对象中......文件内容:
maier ewew 123 232
tudor efsw 13 2323