Joined
·
965 Posts
Greetings,
So I have been messing around again with c++ after my life settled the hell down.
I am writing a text based adventure game (yes, really
), and I want to store the text is seperate notepad files for easy reference and editing.
Here is what I have:
What I cant figure out is how to open a file based on the number I pass to the function via string stf. Originally I was trying to convert int stf into a string and insert it into stftxt, until I realized that I had no good reason to leave it an integer and not make it a string.
Anyways, how do I dynamically open different files depending on a value passed to the function "story"? Any ideas would be most helpful.
Thanks,
TastEPlasma
EDIT: Aww hell, I originally started to type this about a rudimentary save system, but I finally figured all that out (how to read/write arrays to a .txt file). Cant change the threads title now though. :-(
So I have been messing around again with c++ after my life settled the hell down.
I am writing a text based adventure game (yes, really
Here is what I have:
Code:
void story (string stf)
{
string line;
string stftxt = ".txt";
stftxt.insert(0,stf);
ifstream storyfile;
storyfile.open (stftxt);
if (storyfile.is_open())
{
while (! storyfile.eof() )
{
getline (storyfile, line);
cout << line << endl;
}
storyfile.close();
}
else cout << "Unable to open file";
}
Anyways, how do I dynamically open different files depending on a value passed to the function "story"? Any ideas would be most helpful.
Thanks,
TastEPlasma
EDIT: Aww hell, I originally started to type this about a rudimentary save system, but I finally figured all that out (how to read/write arrays to a .txt file). Cant change the threads title now though. :-(