找出正在运行的进程的当前工作目录是什么
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364934(v=vs.85).aspx
例子:
unsigned int length = 0;
char* workingDirectory;
length = GetCurrentDirectory(0, NULL); // How large should my buffer be?
workingDirectory = new char[length]; // Allocate buffer
GetCurrentDirectory( (DWORD) length, (LPTSTR) workingDirectory); // Fill with string
std::cout << workingDirectory << std::endl; // Output string
delete [] workingDirectory; // Make sure to delete it
你可以把它放到一个函数中
void getWorkingDirectory(std::string& dir)
{
unsigned int length = 0;
char* buffer;
length = GetCurrentDirectory(0, NULL);
buffer = new char[length];
GetCurrentDirectory( (DWORD) length, (LPTSTR) buffer);
dir = buffer;
delete [] buffer;
}
注意:我没有测试过这个。