Calculate the length of C++ - style files

You're viewing an older version of this page (#294). View the current version.

View versions (1)

Interface

#include <codecogs/computing/io/binary/file_length_cpp.h>

using namespace Computing::Io::Binary;

The C++ - version of Will Bateman's File_Length

\copydoc binary/file_length

References

fileLength

Example 1

#include <iostream>
#include <fstream>
#include <codecogs/computing/io/binary/file_length_cpp.h>

using namespace std;

int main(int argc, char** argv)
{
        if(argc < 2) return (-1);
        
        fstream a(argv[1]);
        cout <<"The file "<<argv[1]
             <<" is "<<fileLengthCpp(&a)
             <<"bytes long."<<endl;
        return (0);
}

Parameters

file
is a pointer referring to a C++ fstream object.

Returns

fileLengthCpp returns the length of the input file in bytes. On failure it returns -1.
GPL Licence — free for non commercial use. See Licence details.