|
-
May 30th, 2008, 01:45 AM
#1
Thread Starter
PowerPoster
[RESOLVED] File size in standard way
Hi all,
One of my application I used MFC(actually CFile) to find the file size in easy way.
Now I thought to do it using standard C++. Here is my try.
Code:
size_t file_size;
ifstream in_file;
in_file.open("C:\\temo_file.txt", ios_base::in);
if(in_file.is_open())
{
file_size = in_file.seekg(-1, ios_base::end).tellg();
cout << file_size;
}
My question is, this code gives misses one byte. Can you guys give me any reason for it.
Thanks
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
-
May 31st, 2008, 10:01 AM
#2
Hyperactive Member
Re: File size in standard way
Why you have '-1'?
Code:
file_size = in_file.seekg(-1, ios_base::end).tellg();
"Only two things are infinite; the universe and human stupidity, and I'm not sure about the former."
Albert Einstein
-
Jun 1st, 2008, 01:00 AM
#3
Thread Starter
PowerPoster
Re: File size in standard way
ya, I got it. It should be 0.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
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
|