Can a "buffer" be returned by a function?

I am doing a client/server program where the server checks a linked list for results.
How do I get (or is it even possible) one of the functions in the linked list to return
a buffer space?  Like if I wanted the function to search the list and return something like:

setw(30)<<title<<setw(30)<< artist<<endl;

for an undetermined amount of lines (titles and artists)...

Currently my linked list specification function is:
void linkedList::Title(string musicArtist)
        //create pointer called current
       //start at beginning of list ... search until end of list
       //if the current finds a node where artist == musicArtist
       cout<<current->title<<endl;  //print out title
       //so there could be zero to several lines printed out to the screen

But the server needs to take what this function finds and return it to the client.  How do I get it into a buffer instead of printing out to the screen?


I guess I need to change this from "void" to "char" or "string" ...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

using stringstream you can "print" the output to string instead of to screen and then return the string to the client.
stringstream  ss;
string str;
ss << "this is a string" << flush;
str = ss.str();
return str;

if you like to or have to use c-style strings you can wrap it in a buffer struct and return the struct. client can then get it's c-style string from the buffer.

struct buffer{
  char str[BUF_SIZE];
struct buffer buf;
strncpy(buf.str, ss.str().c_str(), BUF_SIZE);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.