copying program arguments to a whitespace separated std::string
<p>I have a Visual Studio 2008 C++ application where I would like to copy all of program arguments in to a string separated by a whitespace " ". i.e., if my program is called as <code>foo.exe \Program Files</code>, then my <code>folder</code> string below would contain <code>\Program Files</code></p>

<p>Below is an example of what I'm doing now. I was wondering if there was a shorter or easier method of doing this. Is there an easy way to eliminate the <code>std::wstringstream</code> variable?</p>

<pre><code>int _tmain( int argc, _TCHAR* argv[] )
{
    std::wstringstream f;
    std::copy( argv + 1,
               argv + argc,
               std::ostream_iterator&lt; std::wstring, wchar_t &gt;( f, L" " ) );
    std::wstring folder = f.str();

    // ensure the folder begins with a backslash
    if( folder[ 0 ] != L'\\' )
        folder.insert( 0, 1, L'\\' );

    // remove the trailing " " character from the end added by the std::copy() above
    if( *folder.rbegin() == L' ')
        folder.erase( folder.size() - 1 );

    // ... 
}
</code></pre>

<p>Thanks,
PaulH</p>
