您的位置:首页 > 其它

获得一个程序在执行时的路径

2012-02-20 13:25 309 查看
  string fullFileName = "";

    // Code taken from: http://www.gamedev.net/community/forums/topic.asp?topic_id=459511
    std::string path = "";

    pid_t pid = getpid();

    char buf[20] = {0};

    sprintf(buf,"%d",pid);

    std::string _link = "/proc/";

    _link.append( buf );

    _link.append( "/exe");

    char proc[512];

    int ch = readlink(_link.c_str(),proc,512);

    if (ch != -1) {

        proc[ch] = 0;

        path = proc;

        std::string::size_type t = path.find_last_of("/");

        path = path.substr(0,t);

    }

    fullFileName = path + string("/");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string path