简体   繁体   English

使用C ++应用程序获取文件名

[英]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. 我有一个C ++应用程序,应该能够读取和解释这些文件。

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? 如果我右键单击其中一个文件,说“打开方式”并选择我的C ++应用程序exe,我如何从应用程序中单击的文件的路径信息?

Thanks! 谢谢!

Windows will in this case run your application with the name of the supplied file as one of its command-line parameters. 在这种情况下,Windows将使用提供的文件的名称作为其命令行参数之一运行您的应用程序。

your_application.exe clicked_file.ext

You probably recall that the main() function has a prototype that goes like 您可能还记得main()函数有一个类似的原型

int main(int argc, char** argv)

This version of main() allows you to handle command-line parameters. 此版本的main()允许您处理命令行参数。 In your case, the name of the file parameter should be at argv[1] . 在您的情况下,file参数的名称应为argv[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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