2

I specifically need to convert an ostream into a string. To be more precise, I have a function:

ostream& f(ostream& out); 

(This function is mainly used for a polymorphic overcharge of the << operator) In this case, I need to get what is in the ostream into the string. After some research, I tried this:

stringstream test;
ofstream tmp;
test << f(tmp);
string foo(test.str());

But the string only contains 0s. Does anyone have a solution for this ?

Thank you

4

1 回答 1

0

尝试使用ostringstream类而不是ofstream

ostringstream test;
test << f(test);
string foo(test.str());
于 2011-05-27T14:30:25.173 回答