May I know if there is a direct way of getting the file size of a binary file (number of characters), using fstream?
Printable View
May I know if there is a direct way of getting the file size of a binary file (number of characters), using fstream?
use fstream::rdbuf()->seekoff( 0, ios_base::end )
Rating isn't important...But gurus respect it and keep high
Hi,
See this#include <iostream>
#include <fstream>
using namespace std;
long GetLenFile(char *szFileName)
{
fstream file(szFileName, ios::in | ios::binary);
if (!file)
{
TRACE("error\n");
return -1;
}
else
{
file.seekg(0, ios_base::end);
streampos nPos = file.tellg();
TRACE("len file = %d\n", (long)nPos);
return (long)nPos;
}
}
// call
long nLen = GetLenFile("readme.txt");
Tell me if that help.
Regards,
Emi.
Sorry, it doesn't help because of the error
"seekoff' : cannot access protected member declared in class 'std::basic_filebuf<char,struct std::char_traits<char> >'"
It works! Cheers mate.
You are welcome.
Regards,
Emi.
Use
m_file.seekg(0, ios_base::end);
long nEnd = m_file.tellg();
Yes, other answers are more helpful
Rating isn't important...But gurus respect it and keep high