Use a serialization library and convert your data into one of the known data formats via that library. I, for instance, use cereal (check the link for an example) library to serialize my data into json format. This is a good list of C++ serialization libraries. Choose the format which suits best for you and then choose a library to serialize and de-serialize the data.
Here is an example of xml serialization with cereal
for your case (edit: compiles now):
#include <cereal/archives/xml.hpp>
#include <sstream>
#include <iostream>
struct SomeData{
int id;
std::string name;
std::string address;
template <class Archive>
void serialize( Archive & ar )
{
ar( id, name, address );
}
};
int main()
{
std::stringstream ss;
// this block is used to make sure the destrcutor of archive is called
// which flushes the output into string stream.
{
cereal::XMLOutputArchive archive( ss );
SomeData myData{4, "name", "address"};
archive( myData );
}
std::string s = ss.str();
// test output
std::cout << s << std::endl;
// send data
send(client.socket, s.c_str(), s.length(), 0);
return 0;
}
This is the output:
<?xml version="1.0" encoding="utf-8"?>
<cereal>
<value0>
<value0>4</value0>
<value1>name</value1>
<value2>address</value2>
</value0>
</cereal>