Reading Custom File Structures

I've been trying to figure out why cout won't print if in a while loop. I already know that the file is being read, and cout works outside of the loop. I need help with this ASAP.

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
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

int main()
{

	ifstream inData("inData.txt");

	if (inData.fail())
	{
		cerr << "Error: File Not Found" << endl;
		
	}


	int l;
	int w;
	int r;
	string nameFirst;
	string nameLast;
	int age;
	double savings;


	while (inData >> l >> w >> r >> nameFirst >> nameLast >> age >> savings)
	{
		cout << l << endl;
	}


	
	
	system("pause");
}
Likely, it wont print because the contents of the file 'indata.txt' does not match the format implied in expression
inData >> l >> w >> r >> nameFirst >> nameLast >> age >> savings
The data is formatted like this:

10.45 8.76
13.78

Jake Melon 45
7600

128 76.9
11

Mike Sander 56
800

15.9 43
6400

David James 32
87000.54

As I understand it, each term (separated by a space) will be assigned a variable in the order that I have them in the while function. I'm guessing that I need something more?
Are you CERTAIN you are reading the right types of data?
Last edited on
Um, how do you mean?
"Types" is the key word.
So... I'm not using the right definitions or...?
Would it be possible to show an example, because I'm completely clueless.
1
2
3
	int l;
	int w;
	int r;


Try guessing again. Third time is the charm.
LOL Kevin!!!

@ Pickles...

Look at what TYPE of data you are reading in, and what TYPE of variables you are declaring

Ah, I'm so dumb! They're doubles, not ints. Thank you. It's working now.
Never say you're dumb on a c++ board, it'll come back to haunt you... :)
Topic archived. No new replies allowed.