I am having some problems in a program that I am trying to make in Visual Studio 2017. The Issue seems to be rooted in my use of the 'stoi()' function in the 'load_pokemon' function. I get the following error when I try to run the program:
Unhandled exception at 0x74A2A932 in ConsoleApplication1.exe: Microsoft C++
exception: std::invalid_argument at memory location 0x010EE918.
The function in question is here (it should be assumed that the Pokemon class is fully functional along with all of the member functions, as I believe that my usage of 'stoi' is the culprit):
void load_pokemon(Pokemon pokemon[]) {
ifstream input_file;
string file_name;
int i = 0;
string temp;
int number;
cout << "\n\nEnter Pokemon Data File Name: ";
cin >> file_name;
input_file.open(file_name.c_str());
while (!input_file.eof()) {
input_file >> temp;
pokemon[i].assign_name(temp);
temp.clear();
input_file >> temp;
pokemon[i].assign_type_1(temp);
temp.clear();
input_file >> temp;
pokemon[i].assign_type_2(temp);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_health_base(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_health_multiplier(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_attack_base(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_attack_multiplier(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_s_attack_base(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_s_attack_multiplier(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_defence_base(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_defence_multiplier(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_s_defence_base(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_s_defence_multiplier(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_speed_base(number);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_speed_multiplier(number);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_1(temp);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_1_effect(temp);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_move_1_max_pp(number);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_2(temp);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_2_effect(temp);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_move_2_max_pp(number);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_3(temp);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_3_effect(temp);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_move_3_max_pp(number);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_4(temp);
temp.clear();
input_file >> temp;
pokemon[i].assign_move_4_effect(temp);
temp.clear();
input_file >> temp;
number = stoi(temp);
pokemon[i].assign_move_4_max_pp(number);
temp.clear();
i++;
}
return;
}
Test read in file:
Bulbasaur grass poison 3 2 4 2 5 3 4 2 5 3 3 2 Tackle physical 5 Vine_Whip
physical 3 Synthesis heal 2 Poison_Powder poison 2
Ivysaur grass poison 4 2 5 2 6 3 5 2 6 3 4 2 Double-Edge physical 5
Vine_Whip physical 3 Synthesis heal 2 Poison_Powder poison 2