Stack Exchange
boost serialiaze archive convert to char
I have successfully serialized an object with the following code:
void aTodo::SendBack(protocolBaseServer & in){
   std::ostringstream archive_stream;
   boost::archive::text_oarchive archive(archive_stream);
   archive << *this;
   std::string outbound_data=archive_stream.str();
//type needs to be first for factory to create correct object
   outbound_data=_initType+outbound_data;
   //now just send it along us
   in.DoWrite(outbound_data);
}

Here is protocolBaseSer DoWrite:
void protocolBaseServer::DoWrite(std::string inMessage){
   _totalMessage=inMessage;
   std::cout << "totalMessage: " << _totalMessage << std::endl;
   int32_t dataLength=_totalMessage.length();
   int32_t orgdataLength=_totalMessage.length();

   std::cout << "data length: " << orgdataLength << std::endl;
   //read in todo
   dataLength = htonl(dataLength ); // Ensure host system byte order on the int;from the network will be network byte order
   std::cout << "writing length now" << std::endl;
   protoService<int32_t>::DoWrite(_sock,&dataLength,sizeof(int32_t));
   std::cout << "written length" << std::endl;
   std::cout << "writing :" << _totalMessage.data() << std::endl;
   protoService<int32_t>::DoWrite(_sock,(void*)_totalMessage.data(),orgdataLength); // send the string dataEE
   std::cout << "wrote :" << _totalMessage << std::endl;

}

Why is it that when I convert my _totalMessage to a c string to send it over the socket it sends nothing.
Also when I attempt to print _totalMessage.c_str() to the screen it prints nothing? here is the output from above.  As you can see the "writing:" line did not display something.  I feel like there is something I am missing to convert this archive to a character array to send over my socket?
writing :
Size to write: 38
wrote :22 serialization::archive 12 0 0 0 0

what is interesting is that the function that preps the string to send does in fact output the "outbound.c: " below:
void aTodo::SendBack(protocolBaseServer & in){
   std::ostringstream archive_stream;
   {  
   boost::archive::text_oarchive archive(archive_stream);
   archive << *this;
   }  
   archive_stream.flush();
   std::string outbound_data=archive_stream.str();
//type needs to be first for factory to create correct object
   std::cout << "outbound: " << outbound_data << std::endl;
   std::cout << "outbound.c: " << outbound_data.c_str() << std::endl;
   outbound_data=_initType+outbound_data;
   //now just send it along us
   in.DoWrite(outbound_data);
}

Edit.
I seem to have found the culprit.
i wanted to prepend a char to the outbound string so I did so like this:
_initType is a const char = 0x01.
It appears you cannot use the + operator to concatenate a const char to a string.  It will mess up the .c_str() return.
void aTodo::SendBack(protocolBaseServer & in){
   std::ostringstream archive_stream;
   {  
   boost::archive::text_oarchive archive(archive_stream);
   archive << *this;
   }  
   archive_stream.flush();
   std::string outbound_data=archive_stream.str();
//type needs to be first for factory to create correct object
   std::cout << "outbound: " << outbound_data << std::endl;
   std::cout << "outbound.c: " << outbound_data.c_str() << std::endl;
   outbound_data=_initType+outbound_data;
   //now just send it along us
   in.DoWrite(outbound_data);
}

I figured it out.
My _initType variable was not being set to 0x01 as i thought.  it was set to 0x00.

To the edit: that should just work. Something else is wrong. I'm starting to suspect generl Undefined Behaviour in your program

Perhaps you need to close the archive before using the results:
{
    boost::archive::text_oarchive archive(archive_stream);
    archive << *this;
}
archive_stream.flush();
std::string outbound_data=archive_stream.str();


i added the flush and the curly brackets and still get nothing on output of _totalMessage.data()
