# std::ifstream on 64-bit OS

This topic is 3885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having some trouble running an MD2 Model Loader on Vista 64-bit. The loader itself works perfectly on 32-bit XP, so I figured all I would need to do is recompile the project in VS2008, sadly it doesn't seem to have had any effect. Here's the relevant section of code:
std::ifstream fFile;

fFile.open(pFilename, std::ios::in | std::ios::binary);

if(!fFile.is_open())
{
return false;
}

{
fFile.close();
return false;
}


The file is opened correctly but when I call std::ifstream::read() all that is placed inside the header is zeros. What am I missing?

##### Share on other sites
My first guess would be that the read call is failing in some way. You aren't checking for that at all. Process Monitor might be useful in tracking down the cause of any file reading problems.

It's also possible that sizeof(S_MD2Header) changes between the two versions, which would obviously mess things up.

Another thing to try would be to use fopen() and fread() instead of ifstream. They are sometimes easier to debug.

A minimal compilable example which shows the problem would be helpful, if those guesses aren't right.

##### Share on other sites
Quote:
 Original post by FunLogicWhat am I missing?

One thing you're missing is the fundmental fact that reading and writing a binary blob like that is inherently non-portable (across architectures, even across different build settinsg from the same compiler on the same architecture). You expectation of success in doing so is misplaced.

I suggest you google for information on object serialization. There are some widely available libraries that could help.

--smw

##### Share on other sites
You could have problems with the S_MD2Header structure, odds are that type sizes and/or alignments have changed. Having said that, that wouldn't cause the contents to be all 0's, you'd get garbage data. Try calling gcount() to see how many bytes were successfully read in the last operation.

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 10
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633402
• Total Posts
3011670
• ### Who's Online (See full list)

There are no registered users currently online

×