设置当前工作路径:
代码:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
char buf[1000];
int i=1000;
GetCurrentDirectory(1000,buf); //得到当前工作路径
cout<<buf<<endl;
char strModule[256];
GetModuleFileName(NULL,strModule, 256); //得到当前模块路径
cout<<strModule<<endl;
string a;
a.assign(buf);
cout<<a<<endl;
a.append("\\..\\"); //设置为当前工作路径为当时的上一级
//a=a+"..\\";
SetCurrentDirectory(a.c_str()); //设置
GetCurrentDirectory(1000,buf);
cout<<buf<<endl;
return 0;
}