Results 1 to 3 of 3

Thread: [RESOLVED] File size in standard way

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Resolved [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

  2. #2
    Hyperactive Member Ivenesco's Avatar
    Join Date
    Sep 2007
    Location
    Poland, Lublin
    Posts
    325

    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

  3. #3

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    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
  •  



Click Here to Expand Forum to Full Width