Hello all, I've stumbled across a slight problem while trying to port some java code to c++. The following java code is:
Code:
...
DataInputStream dis = null;
try {
dis = new DataInputStream (new BufferedInputStream(new FileInputStream("fileblah"))); // create the stream
}
...
try {
int number = dis.readInt();
}
....
Now all the above is doing is reading an interger from the file right? In other words four bytes from a file. So this is the my code in C++: (i'm using stdio, yes yes yes i know, i know?!)
Code:
...
int number;
fread ((char *) &number,4,1,file);
...
However the java code returns: 435
Where as my c++ code returns: -1291780096
Whats going on? I'm still quite a new at all this. Can anyone try and help me port that java code to c++ so it returns the same number! (you don't have to use the standard library).
Thanking you in anticipation,
Adam