Advertisement

Load files ? good, but....

Started by September 18, 2000 11:32 AM
17 comments, last by SKSlayer 24 years, 1 month ago
i recommend using only binaries and no text stuff to store data, u will run into problems with text files that mightnt be apparent at first
Hi, if you do want to use fstream for text input, there a tiny bit you should do

fstream inputFile("inputfile.txt", ios::in | ios::nocreate);

you *must* include | ios::nocreate, under win32 because otherwise, if the file doesn''t exist, it will actually create an empty file, so you cant tell if the file open was successful with if(inputFile.fail()), because it actually creates a new text file.

Under DOS compilers this didnt happen, but I stumbled across this little quirk when trying to get a text file reader going in win32.

Cel
Cel aka Razehttp://chopper2k.qgl.org
Advertisement
Actually, that''s not entirely true, you don''t have to include it in Win32. At least, not if you''re too lazy to create a whole bunch of files then rename them... I mean, if you need to create ten map files but are too lazy to go to explorer and say new file then rename it, then this is the best way since you can just put it in a loop. or a few lines of code or whatever.

Btw, this is post #100!!! Woo hoo! Good for me!

100 posts after being registered for 27 days. Not bad.

S.
Ehehe yeh i spose its a quick way to create empty text files


But seriously, I had no end of trouble detecting whether a text file existed for opening until I figured out the ios::nocreate

Almost drove me insane, coz all the old DOS games I wrote never needed it...

oh well

Cel
Cel aka Razehttp://chopper2k.qgl.org
is there an hexadecimal type in C++ ?


(you can find me on IRC : #opengl on undernet)
No, but to see a value in hex use %x and %X.

%x displays the value with the letters a-f in lowercase and %X displays them in uppercase. You can set the precision in the same way as %f.

int hex = 161;
printf("%.4X", hex);

the above should output ''00F1''

with %.5x it would be ''000f1''
Advertisement
No, but to see a value in hex use %x and %X.

%x displays the value with the letters a-f in lowercase and %X displays them in uppercase. You can set the precision in the same way as %f.

int hex = 256;
printf("%.4X", hex);

the above should output ''00FF''

with %.5x it would be ''000ff''
I''ve got a small binary file "tutorial" that you might want to check out.
http://www.gdarchive.net/bhp/downloads/binarytut.zip
It''s a very simple example, mainly because I felt too lazy to write a lot of lines of code to write/read coordinates that might be a cube .
simon@bhpro.com


||--------------------------||
Black Hole Productions
www.bhpro.com
simon@bhpro.com
||--------------------------||
||--------------------------||Black Hole Productionshttp://bhp.nydus.netResident expert on stuffmax621@barrysworld.com||--------------------------||
I have a small tutorial too!

http://www.lowping.com/demosh/content.php?name=filetut1

~DemOSh

This topic is closed to new replies.

Advertisement