Your program needs to take the file name as argument. Example program:
#include <fstream>
#include <iostream>
#include <limits>
using namespace std;
int main( int argc, char** argv )
{
// Make sure the program has at least two arguments:
// 1: the program's executable path
// 2: the file name passed to your program
if (argc != 2)
return 1;
// Open the argument file
ifstream f( argv[ 1 ] );
// If the file could not be opened, we're done.
if (!f)
return 1;
// This example program just counts the number of lines in the file...
size_t num_lines = 1;
while (f.ignore( numeric_limits <streamsize> ::max(), '\n' ))
++num_lines;
f.close();
// ...and displays the count to the user
cout << "The file \"" << argv[ 1 ] << "\" contains " << num_lines << " lines.\n";
// Keep the console open long enough for the user to see the result.
cout << "Press ENTER to quit.";
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
return 0;
} Hope this helps.