• Advertisement
Sign in to follow this  

What to use for file i/o in c++?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

In c++, what should one use for reading and writing to files?

It can be small text files or a huge 10gb file that stores mucho stuff (something like overly big minecraft world? Not sure if they use a single giant file or if its even possible)

Do people use the standard i/o thingy, stuff from the OS API or some external library?

Thanks

Share this post


Link to post
Share on other sites
Advertisement
Hey friend,

you can use the istream library. Thats actually pretty easy to use. Here are some examples.

http://www.cplusplus...tutorial/files/

You can read textfiles, binary files etc. You can save whole structs in files and read them out easily.

What i also use very often is RandomAccess.

http://cplus.about.c...1/ss/random.htm

If u have more questions. Ask :-)

Bye

Share this post


Link to post
Share on other sites
So i should just use the standard io library thingie? Oh and anyone know where can i find benchmarks and stuff on fixed point vs floating point? Google isnt helping much...

Cant benchmark myself because my computer is broken and i dont trust my code lol.

Share this post


Link to post
Share on other sites

So i should just use the standard io library thingie? Oh and anyone know where can i find benchmarks and stuff on fixed point vs floating point? Google isnt helping much...


Yeah, stick with the standard library for file IO, if you can. If, for some reason, the standard library's file IO fail you, look into Boost's filesystem library. But yeah, stick with the standard library.

As for the fixed point vs floating point... you probably don't need to worry about that too much right now. Most processors have a unit that operates entirely in floating point arithmetic, so they're pretty dang fast. Are you sure you aren't trying to prematurely optimize this by fixed point vs floating point?

Cant benchmark myself because my computer is broken and i dont trust my code lol.

Trust your code. Profile it (but only in your actual game! profiling a simple test case of fixed vs floating point won't do you a whole lot of good). Start writing your game. If things start to run too slowly, profile *your* code, find the bottle neck, and fix it. Remember, it's *your* code that you're trying to make run fast enough, so it's going to have to be *your* code that you profile. But if it's running fast enough there's no sense in optimizing. And there's no sense in optimizing if you don't even have anything working and you don't know what you need to optimize.

Share this post


Link to post
Share on other sites
Im not wanting to make a fixed point class because of performance but because its point doesnt float around xD Thats good for handling forces and such but not position :c

Ill propably end up using floats but i still want to make a fixed point class... Just interested in how they perform against floats, but cant find anything...

Share this post


Link to post
Share on other sites
The very old wisdom (198x and 199x) is that integer operations are faster than floating-point operations because they require simpler circuitry . The slightly old wisdom (200x) is that floating-point operations are faster because there are better SIMD instructions to support them in modern processors. The eternal wisdom is that you should test it both ways and measure.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement