Ofstream not changing target file

I wrote this function to sort an array of library books by their book type (an int from 1-4) and to print out the members of the array in ascending order by book type to the file grouped_record.txt. The program compiles fine but for some reason the file grouped_record.txt remains empty after the program runs. I am sure that the array of library books is filled up correctly as I tested some cout statements to ensure that the array was filled.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  void bookSorter(struct LibraryBook x[], int length)
{
	ofstream bookWriter;
	bookWriter.open("grouped_record.txt");
	for (int i = 1; i <= 4; i++)
	{
		for (int y = 0; y < length; y++)
		{
			if (x[y].type == i)
			{
				bookWriter << x[y].pub_date.month << x[y].pub_date.day << x[y].pub_date.year << endl;
				bookWriter << x[y].author_name.firstname << x[y].author_name.middlename << x[y].author_name.lastname << endl;
				bookWriter << x[y].title << endl;
				bookWriter << x[y].cost << endl;
				bookWriter << x[y].type << endl;
			}
		}

	}
	bookWriter.close();
	cout << "The sorted book list was successfully printed to the file grouped_record.txt" << endl;
	return;
}
I would check the status of bookWriter after the open() call to make sure it opened.
Topic archived. No new replies allowed.