c++ 让你的应用支持相对路径
std::string GetCurrentExeDir()
{
	  char szPath[1024] = { 0 };
#ifdef WIN32
	  GetModuleFileName(NULL, szPath, 1024);
	  char* p = strrchr(szPath, '\\');
#else
	  readlink("/proc/self/exe", szPath, sizeof(szPath));
	  char* p = strrchr(szPath, '/');
#endif
	  *p = 0;
	  return std::string(szPath);
}
BOOL SetCurrentWorkDir(std::string strPath)
{
	  if (strPath.empty())
	  {
		    strPath = GetCurrentExeDir();
	  }
#ifdef WIN32
	  SetCurrentDirectory(strPath.c_str());
#else
	  chdir(strPath.c_str());
#endif
	  return TRUE;
}
先调用GetCurrentExeDir函数获取exe路径,然后使用结果设置SetCurrentWorkDir该函数参数即可,后续在应用程序里面即可使用相对路径
string strDir = GetCurrentExeDir();
SetCurrentWorkDir(strDir);
                    
                
                
            
        
浙公网安备 33010602011771号