How can I know the actual bytes read in a file read

This is a discussion on How can I know the actual bytes read in a file read within the C++ Programming forums, part of the General Programming Boards category; I have a file open for binary read as follow Code: ifstream fin(inFileName, ios::in | ios::binary); fin.read(read_buffer, sizeof read_buffer); Is ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    21

    How can I know the actual bytes read in a file read

    I have a file open for binary read as follow
    Code:
    ifstream fin(inFileName, ios::in | ios::binary);
    fin.read(read_buffer, sizeof read_buffer);
    Is there any way for me to know how many bytes were actually read? Suppose I am on my final read of the file and the number of bytes left is smaller than the size of my read_buffer, I want to know how many bytes of new data I read into the buffer. I thought fin.read() would return an int of number of bytes read but it doesn't. Thanks in advance.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    istream::read() returns the stream. You probably want istream::readsome().
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Reverse Engineering on a Download file
    By c_geek in forum C Programming
    Replies: 1
    Last Post: 03-22-2008, 03:15 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21