Trouble writing to text file

Im trying to write to edit a text file by rewriting the entire file, initially the file is as below, but if i were to change the quantity to eg 19 for one of the variable i waant to rewrite the entire text file by changing one of the quantity. I managed to change it but unable to write the code and name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if (confirm == 'y')
{
							 
outFile.open("tools.txt");
	if (!outFile)
	{
	cout << "\nError opening file.";
	}
	else
	{
	for (int i = 0; i < ToolNum; i++)
	{
		if (i == toolLoc)
		{								 
                   tools[i].quantity--;
		}						 
                outFile.write(tools[i].code, '\0');
                outFile << ",";							 
                outFile.write(tools[i].name, '\0');
                outFile << ",";
		outFile << tools[i].quantity << "\n";
	}
	cout << "\nCheckout successfull.\n";
	outFile.close();
}

This is the text file im trying to produce
1
2
3
4
5
6
101,ladder,20
102,sawing machine,15
103,trolley,10
104,drill,30
105,toolbox,50
106,step ladder,20

This is the text file that i produced
1
2
3
4
5
6
,,19
,,15
,,10
,,30
,,50
,,20

Just do
 
outFile << tools[i].code << "," << tools[i].name << "," << tools[i]quantity << "\n";

The second parameter to write() is a length. '\0' is 0. You're telling write() that you're passing it a buffer of length 0, thus nothing is written.
See my code from your previous post http://www.cplusplus.com/forum/beginner/277054/
Topic archived. No new replies allowed.