I am trying to edit a file called "weaponlevels.txt". It stores data in the format
weapon-weaponlevel
I want to let the user enter a weapon and the preferred level, have the program go through the file until it reaches the entered weapon, and change the weapon level to the level entered by the user.
ostringstream out;
while (getline(infile_ss, line))
{
istringstream ss(line);
getline(ss,weapon,'-');
out << weapon << '-'; // Write the first part of the line.
if (weapon != weaponent)
{ // Not the correct weapon so just write the original information.
ss >> weaponlevel;
out << weaponlevel << endl;
}
else
{ // Found the desired weapon, change the level.
out << temp << endl;
}
}
ofstream outfile("weaponlevels.txt");
outfile << out.str();
outfile.close();