Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions size_of_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <fstream>

using namespace std;

int main (int argc, char* const argv[]) {
if ( argc < 1 )
{
cout << endl << "Usage program name filename" << endl << endl;
return 1;
}
else if ( argc != 2 )
{
cout << endl << "Usage: " << argv[0] << " filename" << endl << endl;
return 1;
}

ifstream file(argv[1]);
if(!file.is_open()) {
cout << endl << "File cannot be opened " << argv[1] << endl << endl;
return 1;
}

long begin, end;

begin = file.tellg();
file.seekg (0, ios::end);
end = file.tellg();

file.close();

cout << endl << "The Size of the File '" << argv[1] << "' is: " << (end-begin) << " Byte." << endl << endl;

return 0;
}