now I prompt the user to pick a character because eventually there will be character names. How would I tell it to access line 1 and write "Frank" instead of <Create Character>?
Secondly, how when the file reads...
Frank
<Create Character>
<Create Character>
<Create Character>
tell the program to change the second line instead of the first? Thanks again you guys are awesome!!! :)
Because I already knew the amount of characters I am letting them create i set the strings from the file into an array, but the process of doing that was what you gave me and it helped out a lot!!! Thanks again Duoas, your the man!!
Here was my approach...
string names[4];
// Read in character names
ifstream charnames(dirName.c_str());
if (charnames.is_open())
{
for (int i = 0; i < 4; i++)
{
getline (charnames, names[i]);
}
charnames.close();
}
if (menuChoice == 'A' && names[0] == "<Create Character>")
{
name = names[0];
charCreate(name);
names[0] = name;
}
if (menuChoice == 'B' && names[1] == "<Create Character>")
{
name = names[1];
charCreate(name);
names[1] = name;
}
if (menuChoice == 'C' && names[2] == "<Create Character>")
{
name = names[2];
charCreate(name);
names[2] = name;
}
if (menuChoice == 'D' && names[3] == "<Create Character>")
{
name = names[3];
charCreate(name);
names[3] = name;
}
// Rewrite character names
ofstream newcharnames(dirName.c_str());
for (int i = 0; i < 4; i++)
{
newcharnames << names[i] << endl;
}
Passing the names to a procedure that creates the character and returns the names, than saves it into the array and rewrites the file...