getting cout output to a std::string

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 <string>  
#include <iostream> 
#include <sstream>   

You can use std::stringstream

http://www.cplusplus.com/reference/iostream/stringstream/


If you can change the code then use ostringstream (or stringstream) instead of cout.

If you cannot change the code and want to "capture" what is being output you can redirect your output or pipe it.

It may then be possible for your process to read the file or get the piped information through shared memory.