File Instream Help!

Hi guys,

My program needs to be able to read some text from a .txt file and then display that information back to the screen. I'm running into a few problems: I'm not sure how to skip the first line of the text file (they are text describing the columns), when I run the code, I get nothing for the seat and the price is something like -9.22e+061. I've looked into the getline ignore but I haven't learned it in class yet. What am I doing wrong here? 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include <iostream>
#include <string>
#include <fstream>

using namespace std;

void Load(string seat[], double price[], int &count)
{
	ifstream in;
	in.open("data.txt");

	for (int i=0; i < 6; i++)
	{
		in >> seat[i];
		in >> price[i];
		count++;
	}
}

int main()
{
	string seat[6];
	double price[6];
	int count = 0;

	Load(seat, price, count);

	cout << "*******************************************" << endl;
	cout << "              TICKET REPORT                " << endl;
	cout << "*******************************************" << endl << endl;

	cout << "There are " << count << " tickets in the database." << endl << endl;
	
	for (int i=0; i < count; i++)
	{
		cout << seat[i] << "" << price[i] << endl;
	}

	system("PAUSE");
	return 0;
}
The only real way to ignore the first line is to read that line and discard the information, getline() is probably the best choice.

The only other option, though not a good one, would be to use a plain text editor and remove that line from your input file.

Topic archived. No new replies allowed.