File String Replace Algorithm... Please

I adapted the code from the following:
http://stackoverflow.com/questions/9505085/replace-a-line-in-text-file

To replace a string in my file with another. The file contents look like the following:

abc 123 0

"äbc"= The username
"123"= Their password
"0"= The amount in their bank

I want to change their bank amount.

But, it isn't working, nor is it even giving me an error code. Can anyone see something that I am missing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	// When the user logs out, make changes to their bank
	string strNew = std::to_string(player.bank); // String representation of the revised player bank
	ifstream filein("user_accounts.txt"); // Old repository of player data
	ofstream fileout("user_accounts_new"); // New repository of player data
	string strTemp; // Temporary string to hold contents to be read from file
	while (filein >> strTemp) // Read the file
	{
		if (strTemp == player.username) // If we are on the correct line..
		{
			filein >> strTemp; // Read their password
			fileout << strTemp; // Write to file.. Bypass it..
			filein >> strTemp; // Here is their previous score
			strTemp = strNew; // Update their score
		}
		fileout << strTemp; // Write to file
	}
	filein.close();
	fileout.close();
Last edited on
Topic archived. No new replies allowed.