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:
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();
}
}
This one appears to be working correctly.
Here's the Function which adds to the list:
Code:
void addSnakeList(snake *save)
{
ofstream fout("snakes/main_list.txt", ios::app);
fout<<(save->nicName)<<"-"<<(save->idNumber)<<endl;
fout.close();
}
Also appears to be working fine.
Here's where i think the problem lies, cause everything works until you run this function and then it gets flipped:
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
}
This is where i believe the problem lies.
Here's where the information is displayed:
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;
}
...
I dont think the problem's here either.
Please help!
Thanks!