neiron21
neiron21

Reputation: 71

How to append string to istringstream?

A websocket server receives messages that need to pass to a function as an std::istream. I am using a istringstream as an intermediate step as:

#include <iostream>
#include <sstream>      // std::istringstream, std::stringbuf
#include <string>
...
std::istringstream _iss;
std::istream &_inputbuff = _iss;

My message handler receives the message as a string and sets _iss.str(message).

This approach does not update the stream with the new blocks of data and as a result the next function samples only the last packet. Is there a way to append to the istringstream instead of setting?

Thank you

Upvotes: 1

Views: 958

Answers (1)

juanma
juanma

Reputation: 1

Better to use std::stringstream and use put(...) function for incoming data (to fill your buffer) and later consume it as you are doing.

stringstream STL reference: https://cplusplus.com/reference/sstream/stringstream/

Upvotes: 0

Related Questions