Slight IFSTREAM trouble!

Simply put; What do I use as the While condition in the () brackets in order for it to loop until every value in the file is read??!

I've tried all sorts...
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
void load()
{//read from file
	ifstream inFile("csv.txt");
	string line;
	
	if(inFile.is_open())
	{
	}
	else
	{
		cout << "Error opening file!" << endl;
	}
	
	while()
		{
			aircraft temp;
			stringstream stream(line);
			stream >> temp.serial;
			stream.ignore ( std::numeric_limits<std::streamsize>::max(), ',' );
			getline(stream,temp.name,',');
			stream.ignore ( std::numeric_limits<std::streamsize>::max(), ',' );
			getline(stream,temp.manufacturer, ',');
			stream >> temp.registration;
			stream.ignore ( std::numeric_limits<std::streamsize>::max(), ',' );
			getline(stream,temp.owner, ',');
			getline(stream,temp.productionDate, ',');
			getline(stream,temp.stdInspection, ',');
			getline(stream,temp.extraInspection, ',');
			mainList.push_front(temp);						
		}
		
		inFile.close();
	
}
Last edited on
Thank you for the reply. I've been to those threads several times but every time my while loop does not break.

!inFile.eof = does not enter loop.
inFile.good() = does not leave loop/
getline(stream, string line) = does not work;

and so on and so on...
stream is not created until you are inside the loop so putting that getline within the while would obviously not make any sense.

I think that you might want something like
while(getline(inFile, line))

It looks like you wish to read the file line by line and then parse each line using a stringstream.
Topic archived. No new replies allowed.