以下是ZeroMQ中使用smessage
方法的代码。我在zhelpers.hpp
头文件中搜索了它的定义,但它不在那里。
#include "zhelpers.hpp"
#include <string>
int main (int argc, char *argv[])
{
// Process tasks forever
while (1) {
zmq::message_t message;
int workload; // Workload in msecs
receiver.recv(&message);
std::string smessage(static_cast<char*>(message.data()), message.size());
std::istringstream iss(smessage);
iss >> workload;
// Do the work
s_sleep(workload);
// Send results to sink
message.rebuild();
sender.send(message);
// Simple progress indicator for the viewer
std::cout << "." << std::flush;
}
return 0;
}
答案 0 :(得分:2)
std::string smessage(static_cast<char*>(message.data()), message.size());
不是对函数smessage
的调用,而是调用构造函数的std::string
变量的定义
basic_string( const CharT* s,
size_type count,
const Allocator& alloc = Allocator() );
答案 1 :(得分:2)
smessage
不是一种方法。它是std::string
类型的变量,它是通过使用带有指针和大小的重载构造函数创建的。
顺便说一句,您可以直接使用zmq::message_t::str()
函数获取std::string
。
例如:
zmq::message_t msg;
// read some data...
std::string smessage = msg.str();