C ++,当一个文件设置为打开你的程序时,你如何获得打开它的文件的路径 [英] C++, when a file is set to open your program how do you get the path of the file that has opens it
问题描述
我想创建一个简单的文本编辑器,然后设置我的所有.txt文件来打开我的prgram。但是当我的程序开始时我需要文件位置以便我可以访问它。
我已经设法返回txt文件所在的文件夹。但似乎无法得到
文本文件名称本身。
例如:myText.txt。
我尝试了什么:
我使用此代码返回txt文件的目录,但我还需要其名称< br $>
char路径[MAX_PATH];
std :: cout<< string(path,GetCurrentDirectory(sizeof(path),path))<< endl;
I want to create a simple text editor and then set all my .txt files to open my prgram. but when my programe starts i need the files location so i can access it.
I have manage to return the folder that the txt file is in. but cant seem to get the
text files name itself.
example: myText.txt.
What I have tried:
I use this code to return the directory of the txt file but i also need its name
char path[MAX_PATH];
std::cout << string(path,GetCurrentDirectory(sizeof(path), path)) << endl;
推荐答案
如果您在Windows
上使用您的程序,那么Explorer
应将文档名称(即文本文件)作为命令行参数传递给应用程序。
If you are using your program onWindows
, thenExplorer
should pass the document name (that is the text file) as command line argument to your application.
列出使用的文件 [ ^ ]
检查主要功能的输入变量或app对象的输入处理程序。应该有完整的路径。
使用调试器。
Check the input variables of the main function or the entry handler of the app object. There should be the full path in it.
Use the debugger.
这篇关于C ++,当一个文件设置为打开你的程序时,你如何获得打开它的文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!