Skip to main content
gamedev.net
🔒 Locked

IO problem

Started by spe 7 replies 300+ views
Original Post
spe
spe
Hi! I''m trying to open a bmp file and read the size of the picture, but somehow it doesn''t work. here is the source : #include "stdafx.h" #include <iostream> #include <fstream> using namespace std; int main(int argc, char* argv[]) { int x,y; ifstream file; file.open("BMP/pic.bmp"); file.seekg(18,ios::beg); file>>x>>y; file.close(); return 0; } the x,y variables aren''t changed at all. Could some one help me with this? Thanks ,spe JSoft@coder.hu
JSoft@coder.hu
C-Junkie
C-Junkie
the >> operators are for text files.

use read() or whatever.
spe
spe
What''s the sintax of read?
JSoft@coder.hu
C-Junkie
C-Junkie
google for istream and you''ll find lots and lots of references
spe
spe
Read is for reading an array of chars, but I need to read two ints.
JSoft@coder.hu
greldik
greldik
Do
read(&x, sizeof(int))
read(&y, sizeof(int))
spe
spe
I tried but I get an error coz x and y are ints and the read func. takes only a pointer to a char.

JSoft@coder.hu
JSoft@coder.hu
spe
spe
It works now with type casting.
Thanks for the help!

JSoft@coder.hu
JSoft@coder.hu

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.