C++获取程序所在目录
#include
#include
#include
using namespace std;
string selfPath();
int main() {
string abspath = selfPath();
cout << abspath << endl;
return 0;
}
string selfPath() {
char buff[1024];
ssize_t len = readlink("/proc/self/exe", buff, sizeof(buff)-1);
if(len != -1) {
buff[len] = '\0';
return dirname(buff);
}
return "";
}