C/C++获取当前路径
2017-03-02 16:07
281 查看
Windows下:
以下内容参考自---点击
string strPath; char chpath[MAX_PATH]; GetModuleFileName(NULL, chpath, sizeof(chpath)); strPath = (string)chpath; int pos = strPath.find_last_of('\\', strPath.length()); strPath.substr(0, pos); std::cout<<strPath.substr(0, pos)<<std::endl; //打印出:E:/C++/cppTest/cppPrimerTest/Debug/
以下内容参考自---点击
#include <windows.h> char chpath[MAX_PATH]; GetModuleFileName(NULL,(LPSTR)chpath,sizeof(chpath)); std::cout<<chpath<<std::endl; //打印出:E:/C++/cppTest/cppPrimerTest/Debug/cppTest.exe #include <direct.h> #include <stdio.h> char buffer[MAX_PATH]; getcwd(buffer, MAX_PATH); printf( "The current directory is: %s ", buffer); //打印出E:/C++/cppTest/cppPrimerTest 打印出全路径: CString path; GetModuleFileName(NULL,path.GetBufferSetLength(MAX_PATH+1),MAX_PATH); path.ReleaseBuffer(); 只提取目录: CString path; GetModuleFileName(NULL,path.GetBufferSetLength(MAX_PATH+1),MAX_PATH); path.ReleaseBuffer(); int pos = path.ReverseFind('\\'); path = path.Left(pos); 只提取exe名: CString path; GetModuleFileName(NULL,path.GetBufferSetLength(MAX_PATH+1),MAX_PATH); path.ReleaseBuffer(); int pos = path.ReverseFind('\\'); int len = path.GetLength(); path = path.Right(len - pos -1);
相关文章推荐
- C++获取当前路径
- C\C++ 获取当前路径
- C\C++ 获取当前工作路径
- C\C++获取当前路径
- c++获取文件夹路径(不是文件哦。。。)及程序当前路径
- c++获取当前路径 向黑客迈进!!!
- C++获取当前路径实现技巧分享
- C++实现获取当前执行文件全路径
- vc6.0 c++获取当前文件夹路径
- 64位系统下C++获取当前所有进程的完整路径
- C++实现获取当前执行文件全路径
- C++设置和获取当前工作路径
- c/c++ 获取当前程序(EXE)所在的路径
- 使用C++获取文件路径,已获取当前路径为基础
- C++获取当前路径
- 使用C++获取文件路径,已获取当前路径为基础
- Windows环境C/C++ 获取当前执行程序路径的两个函数
- C\C++ 获取当前路径
- C/C++获取相对当前启动路径(.exe)下的文件全路径名
- C\C++ 获取当前路径