ftell() - I/O Function

How is "ftell()" used in C++?
How to return current position?


ftell() is an I/O function which returns the current position of the file position indicator for the
specified stream. In binary streams this function returns the number of bytes, but in text stream an output is got using
the fseek() function. When an error occurs "-1" is returned.


long ftell(FILE * stream);


#include <stdio.h>
int main ()
FILE * ptr;
long sz;
ptr = fopen ("freadeg.txt","r");
fseek (ptr, 0, SEEK_END);
sz=ftell (ptr);
fclose (ptr);
printf ("The size of the file in bytes
is::%ld bytes.\n",sz);
return 0;


The size of the file in bytes is::10

In the above example a text stream is read, the "fseek()" function
is used to pass a pointer to get the bytes read as an argument.

C++ Tutorial

Ask Questions

Ask Question