Why is this an infinite loop?

Why does this give an infinite loop and how do I get it to read and cout the other titles correctly?

I have a file with a song titles, the artist and the cost of the album all on separate lines.
Example: orders.txt has the following content.
Turn on the Bright Lights
Interpol
9.49
House of the Jealous Lovers
The Rapture
1.29
etc,...
I have to read these items from the file and place into variables; then cout to console in proper columns.

When I use the while (!inputFile.eof()) I get an infinite loop when I run it in console.
If I don't use the while, I only get the first Title, artist and cost in the correct format.

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

#include <iostream>;
#include <fstream>;
#include <string>;
#include <iomanip>;

using namespace std;

int main()
{

	cout << "Welcome to Jessica Mercer's Online Music Store\n\n";
    cout << "You have submitted the following order: \n";
	cout << "*******************************************************************\n";
    cout << setw(40) << left << "Title " << setw(20) << left << "Artist" << setw(9) << right << "Cost\n";




    ifstream inputFile("orders.txt");
	string title, artist;
    double cost;

	while (!inputFile.eof())
	{
		(getline(inputFile, title));
		cout << setw(40) << left << title;

		(getline(inputFile, artist));
		cout << setw(20) << left << artist;

		inputFile >> cost;
	    cout << setw(7) << right << cost << endl;

	}

	system("pause");
	return 0; 
}
Change line 32 to inputFile >> cost >> ws;

That line leaves a newline in the stream that eventually causes extraction failure in the next iteration of the loop.
Thank you so much! This fixed my problem.
I looked it up to see what the ws was for. We didn't learn about that at all.
Topic archived. No new replies allowed.