-
December 21st, 2000, 04:32 AM
#1
File Size with fstream
May I know if there is a direct way of getting the file size of a binary file (number of characters), using fstream?
-
December 21st, 2000, 04:53 AM
#2
Re: File Size with fstream
use fstream::rdbuf()->seekoff( 0, ios_base::end )
Rating isn't important...But gurus respect it and keep high
-
December 21st, 2000, 05:31 AM
#3
Re: File Size with fstream
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.
Regards,
Emanuel Vaduva
-
December 21st, 2000, 06:19 AM
#4
Re: File Size with fstream
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> >'"
-
December 21st, 2000, 06:27 AM
#5
Re: File Size with fstream
-
December 21st, 2000, 06:32 AM
#6
Re: File Size with fstream
You are welcome.
Regards,
Emi.
Regards,
Emanuel Vaduva
-
December 21st, 2000, 06:33 AM
#7
Re: File Size with fstream
Use
m_file.seekg(0, ios_base::end);
long nEnd = m_file.tellg();
-
December 21st, 2000, 06:53 AM
#8
Re: File Size with fstream
Yes, other answers are more helpful
Rating isn't important...But gurus respect it and keep high
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|