Console Text RPG- File I/O and Inventory
I am attempting to make a console rpg to get some practice before I move any farther in the book I have. I want to know how I can store variables in files and also how I could use an array to store items without using a switch or quite a few if then statements. I've thought about using a class for items.
I dont know how I could use multiple variables in one file because this doesn't seem to work.
Code:
#include <iostream.h>
#include <fstream.h>
void main()
{
int x = 5;
int y = 6;
ofstream a_file("c:\jonsexample.txt");
a_file<<x;
a_file<<y;
a_file.close();
y=0;
x=0; //to change x and y value
ifstream b_file("c:\jonsexample.txt");
b_file>>x;
b_file>>y;
cout<<x<<endl;
cout<<y<<endl;
b_file.close();
}
So my questions are these.
1. What can I do to write a function for an inventory screen and output the item name without using if-then statements or a switch statement (maybe I have to use these) by possibly using an array?
2. How can I write a load/save function by writing an array to a file and then loading the array for character information?
Thank You for your comments.