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

Started by
2 comments, last by MrEvil 18 years, 8 months ago
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
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
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
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).
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.

This topic is closed to new replies.

Advertisement