Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

c++, ifstream read function has been depreciated, what should I be using?

This topic is 4828 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

Hi im reading a file and im using the read function from the 'ifstream' class has been depreciated, so I was wondering what I should be using instead? eg ifstream file("data.txt"); file.read(fileBuffer, fileLength);
Quote:
c:\my\new\nnback\main.cpp(14) : warning C4996: 'std::basic_istream<_Elem,_Traits>::read' was declared deprecated with [ _Elem=char, _Traits=std::char_traits<char> ] c:\program files\microsoft visual studio 8\vc\include\istream(701) : see declaration of 'std::basic_istream<_Elem,_Traits>::read' with [ _Elem=char, _Traits=std::char_traits<char> ] Build log was saved at "file://c:\My\New\NnBack\Debug\BuildLog.htm" NnBack - 0 error(s), 1 warning(s) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
thanks

Share this post


Link to post
Share on other sites
Advertisement
file >> fileBuffer

or

FILE* fp;
fopen("myfile.txt", "rb");
fread(buffer, size, 1, fp);

More info here:
http://www.cplusplus.com/ref/cstdio/index.html

Share this post


Link to post
Share on other sites
ifstream::read hasn't been deprecated; that was a mistake on Microsoft's part - they were a bit overzealous in marking functions as "deprecated". It certainly won't be in the final version of VS 2005 (which is still in beta, remember, so there are bugs).

Share this post


Link to post
Share on other sites
Quote:
Original post by Sfpiano
file >> fileBuffer

Just a pointer (no pun intended[wink]), but on its own, this is just a bit unsafe. If you use this you'll want to call ios_base::width before you do this, in order to avoid buffer overflow exploits.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!