您的位置:首页 > 编程语言 > C语言/C++

C++实现获取当前执行文件全路径

2013-12-20 15:31 253 查看

http://www.cnblogs.com/pegasus923/archive/2010/11/02/1867584.html

用GetModuleFileName(NULL,exeFullPath,MAX_PATH)得到当前执行文件的全路径。


#include <Windows.h>  

#include <iostream>   

#include <string> 

using namespace std;    

     

string GetProgramDir()  

{   

    char exeFullPath[MAX_PATH]; // Full path

    string strPath = "";

 

    GetModuleFileName(NULL,exeFullPath,MAX_PATH);

    strPath=(string)exeFullPath;    // Get full path of the file

    int pos = strPath.find_last_of('\\', strPath.length());

    return strPath.substr(0, pos);  // Return the directory without the file name

}   

 

int main ()

{

    string str = "";

 

    str = GetProgramDir();

    cout << str << endl;

 

    return 0;

}


?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: