字符串传入结构体的实例化中不能直接赋值,也不能用memcpy,需要string_dup()
示例:
msg::Message test_msg;
string text="abc";
test_msg.text = CORBA::string_dup(text.data);//string to uint8_t
message_writer->write(test_msg, DDS::HANDLE_NIL);
text="";//clear
订阅很简单,直接读取string:
msg::Message text_read;
string text_message;
const DDS::ReturnCode_t error = reader_i->take_next_sample(text_read, info); //取得消息内容存入
if (info.valid_data)//仅有有效消息获取到时
{
if (text_read.text != "")//在消息不为空时对接收到的text信息取值
{
text_message = text_read.text;
printf(text_message);
}
}