char path_cur[MAX_PATH] = { 0 }; GetModuleFileNameA(NULL, path_cur, MAX_PATH); std::string path = path_cur; int pos = path.rfind(".."); if (pos >= 0 && pos <= path.size()) { std::string strbuffer = path.substr(pos + 2, path.size());//获取到".."后面的字符串 path.erase(pos + 2, path.size() - 1); //移除".."后面的字符串 path.erase(path.rfind('\\'), path.size() - 1);//移除".." path.erase(path.rfind('\\'), path.size() - 1);//移除".."的上一层目录,保证去除之后还是原路径 path.append(strbuffer.c_str());//添加上开始删除的路径部分 }
原文地址:http://blog.csdn.net/qingzai_/article/details/45073109