Converting ostream into standard string

后端 未结 3 840
温柔的废话
温柔的废话 2020-12-07 16:16

I am very new to the C++ STL, so this may be trivial. I have a ostream variable with some text in it.

ostream* pout;
(*pout) << \"Some Tex         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 16:58

    The question was on ostream to string, not ostringstream to string.

    For those interested in having the actual question answered (specific to ostream), try this:

    void someFunc(std::ostream out)
    {
        std::stringstream ss;
        ss << out.rdbuf();
        std::string myString = ss.str();
    }
    

提交回复
热议问题