stream function output to other stream

Hello, maybe someone can help me with this, i hope.
I'd like to have a function which can stream it's output to an other stream. In the code i have an example function.
Next in my main i'd have a line of code whith console output where i'm calling that function. So:
1
2
3
4
5
6
7
8
9
10
11
void teststream()
{
  std::string testtext = "Hello";
  for ( int i=0; i<testtext.size(); i++)
  {
    std::cout(???) << testtext.c_str()[i];
  } 
}

//Later
std::cout << "Here comes some data: " << teststream();


The question is, can i connect, rederict or pipe the output of teststream(): std::cout(???) to std::cout in the main function line? And if so, how am i going about?
create a global string variable and you can call it from any function.
Topic archived. No new replies allowed.