tmighty
tmighty

Reputation: 11389

C++ Passing a wstringstream to another function

I tried to do the following:

wstring wStringStreamToWString(wstringstream uStream)
{
   wstring s(uStream.str());
   return s;
}

This gives me the compiler error

"C2248 std::basic_ios>_Elem,_Traits>::basic_ios: No access to private members whose declaration was done in std::basic_ios<_Elmen,_Trais>- class."

However, if I do not do this in a separate function, it works fine. So I guess I am simply doing an mistake when I pass the wstringstream to the function, but I don't see which.

Can anybody help?

Thank you.

Upvotes: 2

Views: 123

Answers (1)

hmjd
hmjd

Reputation: 121961

Pass the argument by (const as it is not being modified) reference as streams are not copyable:

wstring wStringStreamToWString(wstringstream const& uStream)
{
    wstring s(uStream.str());
    return s;
}

Though the function, as it stands, seems completely unnecessary.

Upvotes: 4

Related Questions