EOF never turns into true?

Hi,
I tried to read the Cube.obj file (I copy pasted the text)
from
http://www.rastertek.com/dx11tut08.html

But for some reason EOF never become true, and it just loop forever and when I try to debug it, it give me the char value 10 and keep doing so forever.
I also did a similar loop basing on the tutorial, the one which increase vertex count etc. But am not really sure if I can find anything wrong on mine. and when I changed the content inside the text file it worked, so is there anything inside the cube.obj that stop the EOF turning into true?
Here the code I did based on the tutorial
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
	std::fstream modelFile;
	char tempChar;
	modelFile.open(filePath.c_str());
	if(modelFile.fail())
	{
		return false;
	}
	tempChar = modelFile.get();
	while(!modelFile.eof())
	{
		_Model->Model.Total.Test++;
		if(tempChar == 'v' )
		{
			modelFile.get(tempChar);

			if(tempChar == ' ')
			{
				_Model->Model.Total.Vertex++;
			}
			if(tempChar == 't')
			{
				_Model->Model.Total.Triangle++;
			}
			if(tempChar == 'n')
			{
				_Model->Model.Total.Normal++;
			}
			else
			{
				MessageBox(0,"the tempChar is v","Error",MB_OK);
			}
		}
		if(tempChar == 'f')
		{
			modelFile.get(tempChar);
			if(tempChar ==' ')
			{
				_Model->Model.Total.Face++;
			}
		}
		if(tempChar != '\n')
		{
			modelFile.get(tempChar);
		}

	}
Last edited on
Lines 41 to 44:
41
42
43
44
    if (tempChar != '\n')
    {
        modelFile.get(tempChar);
    }

This ensures that the program cannot read beyond the first newline character, doesn't it?

char value 10 is in fact '\n'
Last edited on
Following that page's tutorial, the problem is this:

You wrote:
1
2
3
4
		if(tempChar != '\n')
		{
			modelFile.get(tempChar);
		}

But you should have written:
1
2
3
4
5
		if(tempChar != '\n')
		{
			modelFile.get(tempChar);
		}
		modelFile.get(tempChar);
Last edited on
Topic archived. No new replies allowed.