Q:

Trouble getting working directory

This is how I am trying to get the current working directory:
    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();

Which prints out:
C:\Users\Richard\Documents\Visual

Instead of the actual working directory:
C:\Users\Richard\Documents\Visual Studio 2010\Projects\Client\Debug

It seems like ti cuts everything after a space.
How can I get the working directory correctly even if there are spaces in the path?

A:

Just replace this:
stringstream ss;
string workingDirectory;
ss << ch;
ss >> workingDirectory;

with this:
string workingDirectory(ch);

A:

The >> operator stops at the first space. Instead of the stringstream manipulation try
string workingDirectory(ch);

A:

Use getline(ss, workingDirectory)
The reason that happens is that the << operator in stringstream stops reading when it encounters whitespace.

