Im making a database of mechs for my game series MOTW.
Heres what i have:
Code:
class Mech
{
private:
string name;
string weapon;
string armor;
string first_seen;
string info;
int hp;
int def;
int dam;
int lvl;
public:
void setinfo(char * f);
void outinfo();
};
void Mech::setinfo(char * f)
{
ifstream fin(f);
getline(fin, name, '*');
getline(fin, weapon, '*');
getline(fin, armor, '*');
getline(fin, first_seen, '*');
getline(fin, info, '*');
fin >> hp >> def >> dam >> lvl;
}
void Mech::outinfo()
{
cout << "Name: " << name << endl;
cout << "Armor: " << armor << "\nDef: " << def << endl;
cout << "Weapon: " << weapon << "\nMax Dam: " << dam << endl;
cout << "Avg LVL: " << lvl << "\nFirst seen in: " << first_seen << endl;
cout << "Desc:\n";
cout << info << endl;
}
int main(int argc, char *argv[])
{
Mech mechs[3];
for(int i = 0; i < 3; i++)
{
char * file;
sprintf(file,"%d.mch", i);
mechs[i].setinfo(file);
}
for (int i = 0; i < 3; i++)
{
mechs[i].outinfo();
getche();
}
}
This crashes when i try it. The entire database will have more than 5000 objects, and i dont wanna do Mech mech1; mech1.setinfo(1-3400.mch); etc
Can i do that in a way that i am trying to do it? or do i have to do manual loading of each one?