getting cout output to a std::string

后端 未结 4 1258
死守一世寂寞
死守一世寂寞 2021-02-05 01:38

I have the following cout statement. I use char arrays because I have to pass to vsnprintf to convert variable argument list and store in Msg

4条回答
  •  甜味超标
    2021-02-05 01:46

    You can replace cout by a stringstream.

    std::stringstream buffer;
    buffer << "Text" << std::endl;
    

    You can access the string using buffer.str().

    To use stringstream you need to use the following libraries:

    #include   
    #include  
    #include    
    

提交回复
热议问题