简体   繁体   中英

Getting name of file with C++ application

I imagine this should be relatively simple but I can't find any info about it... I am assuming I just don't know what to search for, but if anyone can help that would be great.

I have some files that I create myself and have given a custom extension. I have a C++ application that is supposed to be able to read and interpret these files.

If I right-click on one of this files, say "Open With" and select my C++ application exe, how do I the path information of the file I clicked on from within the application?

Thanks!

Windows will in this case run your application with the name of the supplied file as one of its command-line parameters.

your_application.exe clicked_file.ext

You probably recall that the main() function has a prototype that goes like

int main(int argc, char** argv)

This version of main() allows you to handle command-line parameters. In your case, the name of the file parameter should be at argv[1] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM