msgpack::object elem; std::string tempString = "string"; elem["type"] = msgpack::pack(tempString);
Above code doesn't work
error: no matching function for call to 'pack(std::string&)'
How can I pack string into msgpack::object?
msgpack::pack() is a free function template in the namespace msgpack:
msgpack::pack()
msgpack
template <typename Stream, typename T> inline void pack(Stream& s, const T& v);
The function obviously is stateless and needs a target where to pack the tempString to. The target can be any class that has the member funciton write(const char*, std::size_t);. For example, use std::stringstream:
tempString
write(const char*, std::size_t);
std::stringstream
std::string tempString = "string"; std::stringstream messagePacked; msgpack::pack(messagePacked, tempString);
And you might want this:
msgpack::object elem; std::string tempString = "string"; elem["type"] = tempString; std::stringstream messagePacked; msgpack::pack(messagePacked, elem);
msgpack::pack()is a free function template in the namespacemsgpack:The function obviously is stateless and needs a target where to pack the
tempStringto. The target can be any class that has the member funcitonwrite(const char*, std::size_t);. For example, usestd::stringstream:And you might want this: