没有获取应用程序名称的应用程序路径在应用程序的结束 [英] Get the App path without the app name at the end of the app

查看:122
本文介绍了没有获取应用程序名称的应用程序路径在应用程序的结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用x code,并希望得到在我的应用程序,而不在路径末尾的应用程序名称运行的路径,但我曾尝试:

I'm using xcode and want to get the path where my app is running without the app name at the end of the path, but i have tried:

printf("%s\n", argv[0]);

这给我在我的应用程序是乳宁正确的路径,但它/我的应用程序名称结尾,我怎么能删除的应用程序的名称?

it give me the right path where my app is runing but it ends with /my app name, how can i remove the app name?

推荐答案

使用目录名

#include <iostream>
#include <libgen.h>

int main(int argc, char* argv[])
{        
    std::string dir = dirname(argv[0]);
    std::cout << dir << std::endl;
}

运行应用程序:

  $/data/temp/test

输出:

  $/data/temp

这篇关于没有获取应用程序名称的应用程序路径在应用程序的结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆