使用readlink讀取當前程序執行路徑
linux中 符號鏈接 /proc/self/exe 爲當前執行路徑的值
#include"unistd.h"
#include"string.h"
using namespace std;
int main(int argc,char **argv)
{
char buf[512];
int length =readlink("/proc/self/exe",buf,sizeof(buf));
if(length<=0)
{
}
string curpath;
curpath.append((char*) &buf,length);
cout<<curpath<<endl;
return 0;
}