Using char argv[] to open a test file and read it [closed]

  argc, argv, c++

I’m trying to open my a text file and read from it using argv[] when I use ifstream input (argv[1]) it doesn’t is there a way i can open the file using argv[1]?

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
    string line;
    cout << argv[1];
    ifstream input (argv[1]);
    while(getline(input, line))
    {

        cout << line << endl;
    }

    input.close();

return 0;

}

Source: Windows Questions C++

LEAVE A COMMENT