ちょっと、その内容が次のテキストファイルを持つことは可能ですか:
Weapon Name: Katana
Damage: 20
Weight: 6
これらの情報を武器クラスのメンバー変数に割り当てることは可能ですか?. メインで getWeaponName を呼び出すと、カタナが取得されますか?
私はグーグルを見回していましたが、テキストファイル全体の入力を取得できますが、どの変数にも割り当てられていません。
私がこれまでに持っているコードは次のとおりです。
Weapons :: Weapons()
{
this->weaponName = "";
this->damage = 0;
this->weight = 0;
}
Weapons :: Weapons(string weaponName,int damage,int weight)
{
this->weaponName = weaponName;
this->damage = damage;
this->weight = weight;
}
void Weapons :: getWeapon()
{
ifstream myfile ("Weapons\\Katana.txt");
string line;
if (myfile.is_open())
{
while (myfile.good())
{
getline (myfile,weaponName,'\t');//This line gets the entire text file.
//getline (myfile,damage,'\t');
//getline (myfile,weight,'\t');
//myfile >> weaponName;
//myfile >> damage;
//myfile >> weight;
cout << weaponName<< "\n";
}
myfile.close();
}
else
{
cout << "Unable to open file";
}
}
前もって感謝します。