Skip to content

Instantly share code, notes, and snippets.

@raarce
Created August 21, 2012 01:00
Show Gist options
  • Save raarce/3410121 to your computer and use it in GitHub Desktop.
Save raarce/3410121 to your computer and use it in GitHub Desktop.
Command line argument example 03
// Command line argument example #03
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
int main ( int argc, char *argv[] )
{
string st;
fstream filestr;
if ( argc < 2 ) {
cout<<"usage: "<< argv[0] <<" <filename>\n";
exit(1);
}
filestr.open(argv[1]);
assert(filestr.is_open());
filestr >> st;
while(!filestr.eof()) {
cout << st << " ";
filestr >> st;
}
filestr.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment