Outputting from text file(FILE HANDLING)

I want to put all of the data in my .txt file to the program to run but my problem is, it outputs only the first two data in my txt file. The rest, it doesn't read.

This is in my .txt file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Assassin's Creed IV:Black Flag /*only this two
29.99                             outputs*/
Murdered: Soul Suspect 
13.49
Middle-earth: Shadow of Mordor Legion Edition 
49.99
Tomb Raider Digital Edition 
9.99
Brothers: A Tale of Two Sons 
3.00
InFaMOUS Second Son 
39.99
Grand Theft Auto V 
59.99
The Last Of Us Remastered 
49.99
The Walking Dead: The Complete First Season 
19.99
Outlast: Bundle of Terror 
28.99
PT 
0.00 


This is my code
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<iostream>
#include<fstream>
#include<iomanip>;
using namespace std;

struct GAMES
{
	char games[100];
	double price;
};

GAMES g[11];
void line(char, int);
void games();

int main()
{
	system("COLOR 9");
	cout << "\n\n\n\n\n\n\n";
	line('=', 80);
	cout << "\n";
	cout << "                          Welcome to PS4 Store!";
	cout << "\n     Please press any key to be able to be redirected to the list of games.";
	cout << "\n\n";
	line('=', 80);
	games();
	system("pause>0");
}

void games()
{
	system("cls");
	system("COLOR 3");
	ifstream fin;
	fin.open("c:\\Transaction\\ps4.txt");
	
	int a = 0;
	for (; a < 10; a++){
		fin.getline(g[a].games, 100);
		fin >> g[a].price;
	} 

	cout << setw(15) << "Games" << setw(35)
		<< "Price";

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	int i = 0;
	for (; i < 10; i++){
		cout << endl;
		cout << setw(15) << g[i].games << setw(35);
		cout << g[i].price;
	}
}

void line(char ch, int ctr)
{
	for (int i = 0; i < ctr; i++) {
		cout << ch;
	}
	cout << endl;
}
Line 40 reads the price, but not the newline character. The second time through the loop line 39 reads the newline and line 40 attempts to read a number but fails. After that none of the reads succeed.

Add cin.ignore( numeric_limits<streamsize>::max(),'\n'); after line 40. This will read and discard all characters through the first newline. You may also need to add #include <limits> at the beginning to pick up numeric_limits<>
It does not work. It still the same. The difference is, it asks me to input multiple stuffs and it outputs the first list and below them are all 0.00
I tried the function newLine(); and it still the same and also tried cin.ignore();
ok this now works...
i added fin.ignore(); on line 41 but the problem is they're not all align... omg
I changed my program a little. But your tip helped me a lot. Thank you!. :)
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
void games()
{
	system("cls");
	system("COLOR 3");
	ifstream fin;
	fin.open("c:\\Transaction\\ps4.txt");

	for (int a = 0; a < 10; a++){
		fin.getline(g[a].games, 100);
		fin >> g[a].price;
		fin.ignore();//i added this part so it will work
	}

	cout << setw(5) << "No."
		<< setw(15) << "Games";

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	for (int i = 0; i < 10; i++){
		cout << endl;
		cout << setw(3) << i + 1;
		cout << "     " << g[i].games;
		cout << "  -   $" << g[i].price;
	}
}
Topic archived. No new replies allowed.