ifstream Issue

Hi i'm having a problem using ifstream. I'm reading from a .dat file which contains 1's and 0's but nothing seems to be coming from the stream, my code is below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	ifstream filein;
	filein.open("myTerrainData.dat");

	if (filein)
	{
		for (int x = 0; x <= 79; x++)
		{
			for (int z = 0; z <= 59; z++)
			{
				filein >> walkability [x][z];
				if (walkability [x][z] > 1) 
				{
					walkability [x][z] = 0;
				}

				printf("\n\n%c\n\n", walkability[x][z]);
			}
		}
		filein.close();	
	}


Printing walkability[x][z] on each loop is just showing up blank in the terminal, any ideas?
printf("\n\n%c\n\n", walkability[x][z]);
You are printing characters with ASCII values 0, which is showed as a blank space.
Thanks, I tried changing the walkability array to an integer array, and now i get a big line of zero's. The problem is that its not reading the data properly, there should be a bunch of one's in there as well. I should mention that myTerrainData.dat can only be edited in a hex editor, it shows as a bunch of null characters in a normal text editor.
Use an char array and "%02x"
Is the data file an ascii file or a binary file? If it's binary, you will need to open the ifstream with the std::ios_base::binary flag. Then you'll read the data 1 byte at a time using get().

Also, what is the data type of the walkability array?

Edit: put question mark at end of question.
Last edited on
Topic archived. No new replies allowed.