获取路径函数
char* GetCurrentPath() {
char currentPath[MAX_PATH] = { 0 };int n = GetModuleFileNameA(NULL, currentPath, MAX_PATH);
currentPath[strrchr(currentPath, '\\') - currentPath + 1] = 0;//将最后一个"\\"后的字符置为0
return currentPath;
}
拼接路径
char *xmlIR = "config.xml";
char pathIR[1024] = { 0 };
strcpy(pathIR, GetCurrentPath());
strcat(pathIR, xmlIR);

本文介绍了一个用于获取当前程序运行路径的函数,并演示了如何利用该函数与字符串操作函数来实现路径拼接,这对于配置文件定位等场景非常有用。
1103

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



