C ++通过套接字连接发送向量

时间:2018-07-07 22:16:52

标签: c++ sockets vector

我正在尝试通过套接字发送向量,但遇到一系列错误,我不确定该如何解决。

向量和通过套接字发送是这样的

 int code = 52;
    std::vector<uint8_t> data1 = { 4, 1, 0, 0, 0, 0, static_cast<uint8_t>(224 + code / 16), static_cast<uint8_t>(code % 16) };

comm_send1 = send(sock, data1.data(), data1.length(), 0);

错误是:

Error (active)  E0167   argument of type "uint8_t *" is incompatible with parameter of type "const char *"  
Error (active)  E0135   class "std::vector<uint8_t, std::allocator<uint8_t>>" has no member "length"    
Error   C2039   'length': is not a member of 'std::vector<uint8_t,std::allocator<_Ty>>' 
Error   C2660   'send': function does not take 3 arguments  

有人可以协助吗?

谢谢

1 个答案:

答案 0 :(得分:1)

send函数除了uint8_t *以外,所以您应该像下面这样转换向量的内容:(const char *)data1.data(); 另外,向量类没有length()方法,应使用size()

相关问题