passing filename as command line argument

Hi there
I am working on a code where from command line user gives the name of the file in which output should be written. The file name is in array av[4]. I am unable to figure out how to make a file by the name stored in av[4] and write simple integer data in to the file.

I would really appreciate any help.


Thanks
1
2
3
4
5
6
7
8
9
10
11
#include <fstream>

int main(int argc, char *argv[])
{
    using namespace std;

    ofstream outputfile(argv[4]);    // open file, assume argv[4] is valid
    outputfile << "some text" << end;  // write some text to the file
    
    return;
}
Topic archived. No new replies allowed.