dirk102
February 16th, 2008, 09:26 PM
Hi.
I'm writing a little communication server and I would like to simplify the building of 'packets'. A packet could send a message, or tell the server to return info on something. I would like to use std::string to store the appropriate data for the packet as my socket wrapper uses it.
How I would like to build the packet is like so:
-code-
int cat=10;
float chicken=1.26;
long monkey=123134;
std::string packet;
packet << cat << chicken << monkey;
-code-
I have looked at std::string stream but it converts anything i throw at it into an ascii representation as so:
packet == "101.26123134"
Is there a ready made solution in the STL for this?
I am trying to avoid using boost.
Or would just constructing my own class for handling this be easiest?
Thank you.
I'm writing a little communication server and I would like to simplify the building of 'packets'. A packet could send a message, or tell the server to return info on something. I would like to use std::string to store the appropriate data for the packet as my socket wrapper uses it.
How I would like to build the packet is like so:
-code-
int cat=10;
float chicken=1.26;
long monkey=123134;
std::string packet;
packet << cat << chicken << monkey;
-code-
I have looked at std::string stream but it converts anything i throw at it into an ascii representation as so:
packet == "101.26123134"
Is there a ready made solution in the STL for this?
I am trying to avoid using boost.
Or would just constructing my own class for handling this be easiest?
Thank you.