获取当前路径

`

#include<iostream>
#include<windows.h>
#include<string>

int main()
{
char buf[100];
//int i = 100;
//LPWSTR 和char类型不兼容
//GetModuleFileName();
GetCurrentDirectoryA(100, buf); //得到当前工作路径
cout << buf << endl;

string a;
a.assign(buf);
cout << a << endl;

a.append("\\..\\.\\data");
cout << a << endl;

int test = SetCurrentDirectoryA(a.c_str()); //设置当前路径值
cout << test << endl;

/*if (test == 0)
{
cout << "execute failed\n";
}
GetCurrentDirectoryA(100, buf);
*/
//--------------------------------------------------------------------//


//这里的两个反斜杠必须加,因为这不是通过操作系统来进行目录切换的
//仅仅是简单的字符串拼接
//*****************************第二种拼接方式**************//
/*strcat(buf, "\\..\\");

cout << buf << endl;
a.assign(buf);
test = SetCurrentDirectoryA(a.c_str());
if (test == 0)
{
cout << "execute failed\n";
}*/

return 0;
}

`

`

#ifdef UNICODE
#define GetCurrentDirectory GetCurrentDirectoryW
#else
#define GetCurrentDirectory GetCurrentDirectoryA
#endif // !UNICODE

`

 

wstring    unique字符集

posted @ 2020-10-17 09:48  点|滴  阅读(3)  评论(0)    收藏  举报