Trouble loading saved data

Never mind, figured it out. told it to only use 4 array indexes when it needed 5


I am making a text game and am breaking it up into small sections. But i am having trouble loading the fifth string of saved data (by trouble, i mean it crashes every time)
Its rather messy, i know. Replaced long talking parts with 'blahblah'.
Program im using to try to load data is below the game.

game:

#include <iostream>
#include <fstream>
using namespace std;

string Rattata ();
string Pidgey ();
string Magikarp ();
string PinkiePie ();
string OAK ();
string begining1 (){
string name;
cout << "blah blah ";
cin >> name;
cout << "Right, so your name is " << name << " ... ... i woulda picked Quinn myself.";
return name;
}
string begining2 (string rival_gender){
string name, rg1, rg2;
if (rival_gender == " he "){
rg1= " him ";
rg2= " his ";
}
else {
rg1= " her ";
rg2= " her ";
}
cout << " blah blah ";
cin >> name;
return name;
}
string Pokemon (string r_n){
string help= "Type the name of the pokemon you chose. Type pokedex_pokemon name (ie. pokedex_rattata) for a pokemons stats.", pokemon="n/a", answer, pokedex_info;
cout << " Ok, so i gave " << r_n << " blahblah
cout << "\n*type help for help at any time*\n|rattata\n|pidgey\n|magikarp\n" << help << endl;
while (pokemon =="n/a"){
cin >> answer;
if (answer=="help"){
cout << help;
}
if (answer=="pokedex_rattata"){
pokedex_info= Rattata ();
cout << pokedex_info;
}
if (answer=="pokedex_pidgey"){
pokedex_info= Pidgey ();
cout << pokedex_info;
}
if (answer=="pokedex_magikarp"){
pokedex_info= Magikarp ();
cout << pokedex_info;
}
if (answer=="pokedex_OAK"){
pokedex_info= OAK ();
cout << pokedex_info;
}
if (answer=="pokedex_PinkiePie"){
pokedex_info= PinkiePie ();
cout << pokedex_info;
}
if (answer=="OAK"){
cout << "Wait! WHAT?!\n";
}
if ((answer=="rattata")||(answer=="pidgey")||(answer=="magikarp")||(answer=="PinkiePie")){
pokemon=answer;
}
else{
cout << "\nPlease chose a pokemon. ";
}
}
return pokemon;
}
string Rattata (){
string info="RATTATA: 1'0\" 8 LBS\n\"WILL CHEW ON ANYTHING WITH ITS FANGS. IF YOU SEE ONE, IT IS CERTAIN THAT 40 MORE LIVE IN THE AREA\"\n|TACKLE\n|TAIL WHIP\n|QUICK ATTACK (LV9)\n|HYPER FANG (LV14)\n|FOCUS ENERGY (LV23)\n|SUPER FANG (LV34)";
return info;
}
string Pidgey (){
string info="PIDGEY: 1'0\" 4 LBS\n\"VERY DOCILE. IF ATTACKED, IT WILL OFTEN KICK UP SAND TO PROTECT ITSELF RATHER THAN FIGHT BACK.\"\n|GUST\n|SAND-ATTACK (LV5)\n|QUICK ATTACK (LV12)\n|WHIRLWIND (LV19)\n|WING ATTACK (LV28)\n|AGILITY (LV36)\n|MIRROR MOVE (LV44)";
return info;
}
string Magikarp (){
string info="MAGIKARP: 2'11\" 22 LBS\n\"FAMOUS FOR BEING VERY UNRELIABLE. IT CAN BE FOUND SWIMMING IN SEAS, LAKES, RIVERS, AND SHALLOW PUDDLES.\"\n|SPLASH\n|TACKLE (LV15)";
return info;
}
string PinkiePie (){
string info="PINKIE PIE: 3'4\" ? LBS \n\"CAUTION: LOVES PARTIES LIKE THERES NO TOMORROW.\"\n|PARTY TIME\n|PUPPY EYES\n|SUGAR OVERLOAD (LV12)";
return info;
}
string OAK (){
string info="Some old guy with failing eyesight.";
return info;
}
string beginning3 (string x){
string nickname="n/a", answer, help="type y to give your pokemon a name, and n to not name it. Remember, nicknames ARE permanent.";
cout << " Do you want to give "<<x<<" a nickname?(y/n)";
while (nickname =="n/a"){
cin >> answer;
if (answer=="help"){
cout << help;
}
if (answer=="y"){
cout << "What would you like to name " << x << ": ";
cin >> nickname;
cout << nickname <<", huh. Well, ok then.\n";
}
if (answer=="n"){
nickname=x;
}
if (nickname=="n/a"){
cout << "Do you want to give "<<x<<" a nickname? (y/n)";
}
}
return nickname;
}



int main (){
cout << "Before we get started, how about some info. Gender? (male/female): ";
string main_name, rival_name, gender1="n/a",gender,rival_gender,pokemon1nn, pokemon1;
while (gender1=="n/a"){
cin >> gender;
if (gender=="male"){
gender1=" Mr. ";
rival_gender=" she ";
}
if (gender=="female"){
gender1=" Ms. ";
rival_gender=" he ";
}
if (gender1 == "n/a"){
cout << "Um, try that again. male or female: ";
}
}
main_name = begining1 ();
cout << "\nWelcome " << main_name;
rival_name = begining2 (rival_gender);
pokemon1 = Pokemon (rival_name);
cout << "Hmm... well, i wouldn't have chose "<<pokemon1<<", but if you really want it.";
pokemon1nn = beginning3 (pokemon1);
cout << "blah blah";
system("PAUSE");
cout << "SYSTEM ERROR: TOO AWESOME TO COMPUTE! WILL HAVE TO CONTINUE IN NEXT CHAPTER!\nEND POKEMON: THE TEXT ADVENTURES: PROLOUGE (PART 1 OF 2)\n";
cout << "blahblah";
ofstream save_data("save_data", ios::out);
string useless="n/a";
string all [6]={main_name,gender,rival_name,pokemon1,pokemon1nn,useless};
save_data <<all [0] << endl << all [1]<< endl << all [2]<< endl << all [3]<< endl << all [4] << endl << all [5];
cout << "Saved data is: name: " << all [0] << ", gender: " << all [1] << ", rival's name: " << all [2] << ", your pokemon: " << all [3] << "your pokemon's nickname: " << all [4] << endl;
system("PAUSE");
return 0;
}

'Experimenting' loading data program:

#include <iostream>
#include <fstream>
using namespace std;
int main(){
string data_info[4]; // pokemon1, pokemon1nn, main_name, rival_name, gender;
ifstream save_data("save_data");
save_data >> data_info [0] >> data_info [1] >> data_info [2] >> data_info [3]>>data_info [4];
cout<<data_info [0]<<" "<<data_info [1]<<" "<<data_info [2]<<" "<<data_info [3]<<" "<<data_info [4];
system("PAUSE");
return 0;
}
Last edited on
Topic archived. No new replies allowed.