std::ftell
From cppreference.com
Defined in header <cstdio>
|
||
long ftell( std::FILE* stream ); |
||
Returns the current value of the file position indicator for the file stream stream
.
If the stream is open in binary mode, the value obtained by this function is the number of bytes from the beginning of the file.
If the stream is open in text mode, the value returned by this function is unspecified and is only meaningful as the input to std::fseek.
Contents |
[edit] Parameters
stream | - | file stream to examine |
[edit] Return value
File position indicator on success or -1L if failure occurs. Also sets errno on failure.
[edit] Notes
On Windows, _ftelli64
can be used to work with files larger than 2 GiB.
[edit] Example
Demonstrates std::ftell()
with error checking. Writes then reads a few floating-point (FP) values to/from a file.
Run this code
#include <cstdio> #include <cstdlib> #include <iostream> // If the condition is not met then exit the program with error message. void check(bool condition, const char* func, int line) { if (condition) return; std::perror(func);