程序.exe的路径: CString strPath; GetModuleFileName( NULL, strPath.GetBuffer(MAX_PATH), MAX_PATH ); //NULL 返回应用程序的全路径 strPath.ReleaseBuffer(); //清空缓冲区 strPath = strPath.Left(strPath.ReverseFind(_T('\\'))); //获取整个路径 获取程序的工作路径,上面的是默认路径: int i = GetCurrentDirectoryW(0,NULL); //先把两个参数设为,NULL用来返回目录的字符数. WCHAR dir[100]; //关键就在这里, 函数定义中第二个参数用来保存目录的字符串,类型为LPTSTR,如果我们直接声明一个变量LPTSTR dir的话,能通过编译,但是在执行的时候会发生access violation的错误.(我声明的char dir[100]vc++.net 2005中只得到路径的第一个字母,改为WCHAR后问题解决。----zskcy) GetCurrentDirectory(i,dir);
C++ 路径问题
猜你喜欢
转载自blog.csdn.net/sheyun1876/article/details/80583470
今日推荐
周排行