Acmlm's Board - I2 Archive - Programming - File reading problem [C++]
User | Post |
Smallhacker
Posts: 2068/2273 |
Thanks. It works perfectly now. |
Eponick
Posts: 27/37 |
Just do is.open("c:\\ZRO_lv.txt", ifstream::binary);
That should work |
HyperLamer
Posts: 6864/8210 |
You've opened it in text mode. 0A is a newline character, so it may be converting it to 0D0A or something like that. I'm not sure how to open it in binary mode, though, since I just use fopen().
Also, I wrote a program like this and I found I had to do map[y][x] = blah. |
Smallhacker
Posts: 2060/2273 |
I'm trying to make a small game, since I need training in C++ programming. However, what's a game without levels? Therefore, I need code which reads the level data from a file.
(using fstream.h)
ifstream is; is.open ("c:\\ZRO_lv.txt"); for (int yy=1;yy<26;yy++){ for (int xx=1;xx<61;xx++){ if (!rep){ is.get(rep); is.get(readblk); is.get(readcol); }else{rep--;} map[xx][yy].chr=Blockchar(readblk); map[xx][yy].col=readcol; } } is.close();
(File format, in case somebody wonders: Byte 1 = How many times to repeat the two following bytes. Byte 2 = Block number. Byte 3 = Block color)
However, for some reason, something goes wrong when it comes across a 0x0A byte, which seems to cause it to read junk instead of file data.
Can anyone tell me what the problem is? |
|