March 9th, 2010, 10:17 PM
fstream.get() - Problem
Hi! I'm trying to read a text file one character at time, but the fstream get() function read some crap after the character. Here is my code:
for (int i = 0; i < MAP_SIZE; i++)
for (int j = 0; j < MAP_SIZE; j++)
file.get(a); // reads a char
char* b = const_cast<char*>(&a); // convert to no-const
textout_ex(screen, font, b, x, y, makecol(0, 0, 0), makecol(255, 255, 255)); // print it
x += 20;
x = 250;
y += 20;
The text file is just chars, like this:
The code seems to work fine, but for somereason i get this:
0^ ^^0^1^1^0^0^0^0^0^0^0^0^1^0 D
... and continues.
Please! What i'm doing wrong?
I'm just wanna read a text file one char at time.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!