这是我想获得当前的工作目录:麻烦的工作目录
char* ch;
if((ch = _getcwd(NULL, 0)) == NULL)
{
cout << "Could not get working directory!" << endl;
}
// skonvertujme char* na string, s tym sa nizsie bude lahsie pracovat
stringstream ss;
string workingDirectory;
ss << ch;
ss >> workingDirectory;
cout << workingDirectory << endl;
cin.get();
cin.get();
打印出:
C:\Users\Richard\Documents\Visual
而不是实际的工作目录:
C:\Users\Richard\Documents\Visual Studio 2010\Projects\Client\Debug
似乎ti在空间之后切割一切。
即使路径中有空格,我如何正确地获取工作目录?
为什么使用字符串流呢? – 2010-12-14 21:03:18
是的,你是对的。 – 2010-12-14 21:21:28