how to open a file alongside an executable

in a program i need to make one of the requirements is to open the program along side the executable using the terminal and c++:

./program.exe FILENAME.txt

i can get the program to open the .txt file inside of the program so the user doesnt have to type the file name but it is not what is needed. i already included the fstream library in my program.

thank you in advance to anybody who can help me out.
Google "c++ main argc argv"
Thank you Texan40 i was not sure what this was called.
1
2
3
4
5
6
7
8
9
10
int main(int argc, char* argv[])
{
    if (argc < 2) return 1;

    ifstream fin(argv[1]);

    //fin is now an object like cin, except that it uses the file as a buffer.

    return 0;
}
Last edited on
Topic archived. No new replies allowed.