int main() {
vector<material_t> M;
vector<dryMaterial_t> DM;
ifstream ifs("testFile");
material_t m;
dryMaterial_t dm;
//????????????????????????????????????????????????????????????
//Read in stuff
//if encounter Material: then ifs>>m; M.push_back(m);
//if encouter DryMaterial: then ifs>>dm; DM.push_back(dm);
//????????????????????????????????????????????????????????????
ifs.close();
for(int i=0; i<M.size(); i++) {
cout<<M[i];
}
for(int i=0; i<M.size(); i++) {
cout<<DM[i];
}
return 0;
}
The comment part is what I don't know how to implement, although I asked some question about ignoring text and capture number before, I still cannot figure this out. Please help me out, thank you very much!
You can use the std::string functions to parse each line and then do a string compare against your criteria i.e. if( strcmp("Material:", str_material.c_str()) == 0) //Do stuff
Stuff could be that you populate your material class with the type and density then push it into the vector or do a vector.resize(vector.size() + 1, obj);