CString path_exclusive_exe, path_lnclude_exe;//含有.exe的路径和不含的
GetModuleFileName(NULL, path_lnclude_exe.GetBuffer(MAX_PATH), MAX_PATH);
path_lnclude_exe.ReleaseBuffer();
for (int i = 0; i <path_lnclude_exe.GetLength(); i++)
{
if (path_lnclude_exe[i]=='\\')
{
path_lnclude_exe .Insert(i,'\\');//填充,使得‘\’变为‘\\’
i = i + 2;
path_exclusive_exe = path_lnclude_exe.Left(i);//不含xxxx.exe
}
}
//以上为获得执行文件的绝对路径,含xxxx.exe
本文介绍了一种在C++中获取当前执行文件绝对路径的方法,包括如何处理路径中的特殊字符,如将单个''转换为'\',并从中提取不含文件名的目录路径。
3578

被折叠的 条评论
为什么被折叠?



