Ok, I am making a character creation program to assist my cousins game he is making. I need to be able to save thigs like character name, class, race, and ect,ect to a file. And then be albe to make a code to load the information into the game. I can get it to save to a .txt file with <ofstream> but I cant figure out how to load the information I saved to the .txt. I also need to be able to figure out how to utilize .ini files to configure ingame options. I am putting the character creation code up here to show how I am saving the stuff to a file but...I deleted all attempts at accessing and loading info from the file thanks ALOT in advance.
Code:
/*******************************************************************************
Ok, This is strictly here for the C Boards forum. The Only selection that works
is the Create Character. I dont want to write all the code a right now so I just
made the program work not be complete. If you choose any option besides create
character it will just loop back to the menu until you choose create character.
Well as far as I know you are all alot smarter than me so I havent much more to
say as far as how the program works and such it is easy to read and figure out.
*******************************************************************************/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
float vn;
int a[10];
int z[3];
vn = 1.01;
string races[11] = { "Troll", "Titan", "Firbolg", "High Elf", "Half-Elf",
"Dwarf", "Ogre", "Iskar", "Human", "Melerrian", "Sylph"};
string names[12] = { "Raigne", "Centrea", "Valos", "Sathias", "Maria", "Sarah",
"Gonalas", "Sentrus", "Darivas", "Verinias", "Burlon", "Garlonsus",};
cout << "*******************************************************************\n";
cout << "* Xinathian Character Creator V " << vn << "b!!! *\n";
cout << "*******************************************************************\n";
do {
if ( z[1] == 1 ) { system("cls"); }
cout << "***********************\n";
cout << "*(1) Create Character * Make A New Character\n";
cout << "*(2) Modify Character * Modify An Existing Character\n";
cout << "*(3) Options * Change Options for game\n";
cout << "*(4) Exit * Exit Program\n";
cout << "***********************\n";
cout << "Selection: ";
cin >> a[1];
switch ( a[1] ) {
case 1:
cout << " Make A New Character? \n";
cout << " (1) Yes (2) No \n";
cout << " Selection: \n";
cin >> a[2];
if ( a[2] == 1 ) {
ofstream a_file ( "Character.ini" );
cout << "Ok.. Please Select Your Race\n\n";
for ( int x = 0; x < 10; ++x ) {
if ( x == 7 || x == 14 || x == 21 ) {
cout << "\n";
}
cout << x + 1 << ") " << races[x] <<" ";
if ( x == 9 ) { cout << "\n\n"; }
}
cout << " Your Selection Please: ";
cin >> a[3];
cout << " You Chose "<< races[a[3] - 1] <<"\n Is this correct?!";
cout << " (1) Yes (2) No";
cout << " Selection: ";
cin >> a[4];
if ( a[4] == 1 ) {
a_file << ( races[a[3] - 1] );
cout << " Ok choose your character name please. \n\n";
for ( int t = 0; t < 12; ++t ) {
if ( t == 7 || t == 14 || t == 21 ) {
cout << "\n";
}
cout << t + 1 << ") " << names[t] <<" ";
if ( t == 11 ) { cout << "\n\n"; }
}
cout << "Your Selection Please: ";
cin >> a[5];
cin.ignore();
cout << "You Chose "<< names[a[5] - 1] <<" For Your Name.";
a_file <<"\n";
a_file << ( names[a[4] - 1] );
cin.get();
return 1;
}
else {
cout << " Ok returning to menu";
z[1] = 1;
}
cin.get();
}
else {
cout << "Ok returning to menu";
z[1] = 1;
}
case 2:
z[1] = 1;
break;
case 3:
z[1] = 1;
break;
case 4:
return 1;
break;
default:
z[1] = 1;
break;
cin.get();
}
} while ( z[1] == 1 );
cin.get();
}
EDIT: OK, that is the new code opposed to the EXTREMELY long one before. this should help you guys to help me ( or so I hope ). Well anyways I posted once at the bottom so you might read that before you read this. Well I hope you guys can help me Thanks Alot. Maybe someday Ill be able to returnthe favor.