Search code examples
c++windowswinapifstreamifstream

read the file that is opened with my console application in C++


I have written a console application in C++ and I need to read the file that is opened with my console app:

  • right click on txt file
  • select open with
  • choose my console application

then I want to read that .txt file. how?

my source code


Solution

  • You just need to declare arguments to your main like this:

    int main(int argc, char *argv[])
    {
       ...
    }
    

    And the file path will be passed as one of the argument. If you open multiple files, it will run one process per file.