Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass a stringstream as a function parameter?

Tags:

Is it possible to pass in a stringstream and have the function write to it directly?

I remember I saw a function invoked similar to something like this:

my_func(ss << "text" << hex << 33); 
like image 315
rsk82 Avatar asked May 31 '12 12:05

rsk82


People also ask

Can we use Stringstream in C?

How to Perform Extraction or Read Operation in StringStream in C++ Like the insertion, we can also perform extraction on StringStream in C++, like the cin >> operator. We can again do this by using the >> operator or the str() function.

Can you return a Stringstream?

You can't return a stream from a function by value, because that implies you'd have to copy the stream.

What is the difference between string and Stringstream?

Very Informally: A string is a collection of characters, a stream is a tool to manipulate moving data around. A string stream is a c++ class that lets you use a string as the source and destination of data for a stream.

How does a Stringstream work?

The stringstream class in C++ allows a string object to be treated as a stream. It is used to operate on strings. By treating the strings as streams we can perform extraction and insertion operation from/to string just like cin and cout streams.


1 Answers

Sure thing. Why wouldn't it be? Example declaration of such function:

void my_func(std::ostringstream& ss); 
like image 127
eq- Avatar answered Nov 29 '22 08:11

eq-