Okay so i'm writing this program to keep track of snakes for breeders and large-scale collectors.
The problem is that for some reason it's flip-flopping the ID numbers and the Names.
Here are the functions and code chunk which uses this function:
This function loads the entire list into 2 vectors:
This one appears to be working correctly.Code:void loadSnakeList(vector<string> &ids, vector<string> &names) { ifstream fin("snakes/main_list.txt"); vector<string> v; string temp; while(getline(fin, temp)) { v.push_back(temp); } fin.close(); int size = v.size(); string tname, tnum; bool flag = false; for(int i=0; i<size; i++) { for(int j=0; j<v.at(i).size(); j++) { if(v.at(i).at(j) == '-') { flag = true; } else if(flag == false) { tname.push_back(v.at(i).at(j)); } else if(flag == true) { tnum.push_back(v.at(i).at(j)); } } ids.push_back(tnum); names.push_back(tname); flag = false; tnum.clear(); tname.clear(); } }
Here's the Function which adds to the list:
Also appears to be working fine.Code:void addSnakeList(snake *save) { ofstream fout("snakes/main_list.txt", ios::app); fout<<(save->nicName)<<"-"<<(save->idNumber)<<endl; fout.close(); }
Here's where i think the problem lies, cause everything works until you run this function and then it gets flipped:
This is where i believe the problem lies.Code:void deleteSnakeFile(string file) { string rem= "/snakes/"+file+".dea"; remove(rem.c_str()); //remove from list vector<string> rnames; vector<string> rums; loadSnakeList(rums, rnames); //Search int pos; for(int i=0; i < rums.size(); i++) { if(rums.at(i) == file) { pos = i; } } //Rewrite file ofstream fout2("snakes/main_list.txt"); for(int i=0; i<rums.size(); i++) { if(i != pos) { fout2<<rums.at(i)<<"-"<<rnames.at(i)<<"\n"; } } fout2.close(); //Done }
Here's where the information is displayed:
I dont think the problem's here either.Code:... clr(); setColor(BLUE, WHITE, h); cout<<" "; cout<<" ANIMALS "; cout<<" "; cout<<endl; setFontColor(NORMAL, h); //CONTENT HERE!!!!!!***** vector<string> ids; vector<string> names; loadSnakeList(ids, names); for(int i=0; i<ids.size(); i++) { setFontColor(WHITE, h); cout<<" "<<ids.at(i); setFontColor(NORMAL, h); cout<<" -> "; setFontColor(GREEN, h); cout<<names.at(i)<<endl<<endl; } ...
Please help!
Thanks!



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.