Allegro - how do I read data from a normal ascii file?

Started by
15 comments, last by darenking 18 years, 10 months ago
That works!

Trouble is, although the first integer I'm saving in my BlitzBasic mapper program is the integer 646 (just as a test), when I load in the integer in my C++ file in DevC, it loads in the value 4406688. What could it all mean?

Maybe DevC and Blitz handle integers differently? I don't know much about that sort of thing.

Here is how I create the file in Blitz:

fileout = WriteFile(CurrentDir$()+"testfile.dat")
WriteInt( fileout, 646 )
CloseFile(fileout)

Then here is how I load it in C++:

int data;
std::ifstream file("testfile.dat");
file >> data;
file.close();

Any clues???
Advertisement
My guess is that it is being stored in binary. Go to the file and open it with notepad (Windows will bitch at you about "not being able to open this file", but ignore that[smile]).

If you can see the 646 it's a text file, if it's not readable, it's being stored in binary...

<edit>
If it is stored as binary, try this code:
int data;std::ifstream file( "testfile.dat", std::ios::binary );file.read( (char*) &data, sizeof(int) );
</edit>
It works!!!

You're a genius.

How can I ever repay you?


Quote:Original post by joebarnslondon
It works!!!

You're a genius.

How can I ever repay you?


Well you could rate me up...[smile]

Glad to help!
How do I do that?
Click the Rate User option at the bottom of his post.
My Current Project Angels 22 (4E5)
Cleverly done!

This topic is closed to new replies.

Advertisement