iobinary

file Length Cpp

Freely available under GPL terms only
get a GPL licence
viewed 4192 times and licensed 51 times
www.codecogs.com/d-ox/io/binary/file_length_cpp.php
Controller: CodeCogs    Contact Controller

Interface

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

int fileLengthCpp (std::fstream * file)
Calculate the length of C++ - style files

Function Documentation

 
intfileLengthCppstd::fstream*file )
The C++ - version of Will Bateman's binary/file_length

Returns the length of a file in bytes. Useful when you need to dynamically allocate memory to hold the contents of a file you intend to read. This function was designed to replicated the similarly named filelength function that comes with some distributions of C/C++, particularly on DOS platforms. There doesn't appear to be an equivalent in Unix.

References:
fileLength
Example:
#include <iostream>
#include <fstream>
#include <codecogs/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:
fileis a pointer referring to a C++ fstream object.
Returns:
fileLengthCpp returns the length of the input file in bytes. On failure it returns -1.
Authors:
Robert Schwede
Source Code:
Register

- To get code register with CodeCogs. Already a Member, then Login.


Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2008-05-09 08:37:27

Page Comments

  You must login to leave a messge


Valid CSS!   Valid XHTML 1.0 Transitional