input from ./a.out <filename> command

So I am a student and I am just learning how to play with fstream and my instructor wants us to turn in a single .cpp file. the file will be implemented using ./a.out <filename> from a Linux console. I just assumed it was like passing a value from a main function.

first off I an error on line 20 (if it numbers it if not the last line:
infile.open(filename.c_str);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <string>
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;
void allCount(ifstream&);
//so we have ./a.out filename

void allCount(ifstream& filename)
{
    int words = 0,
        charater = 0,
        line = 0;
    string nspace;
    string space = " ";
    string dspace = "  ";
    
    ifstream infile;
    infile.open(filename.c_str);


so first off I cannot run it and also i am not sure if this is how you input from command line. basically the idea is that you can select the file from command line and run it

Please help as I have spent alot of time searching already
ifstream does not have a .c_str() member. You are probably want a std::string here, or, knowing how command line arguments are passed to main(), plain old char* might work too.
Topic archived. No new replies allowed.