c ++向量< char>和插座 [英] c++ vector<char> and sockets

查看:102
本文介绍了c ++向量< char>和插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以在向量中调用send / recv传递?

Is there a way to call send / recv passing in a vector ?

在c ++中缓冲套接字数据的好办法是什么?例如:直到\r\\\
或直到上限(4096字节)

What would be a good practice to buffer socket data in c++ ? For ex: read until \r\n or until an upper_bound ( 4096 bytes )

推荐答案

std::vector<char> b(100); 
send(z,&b[0],b.size(),0);

:I second Ben Hymers' me22的评论。另请参阅此回答通用实现,不尝试访问空向量中的第一个元素。

Edit: I second Ben Hymers' and me22's comments. Also, see this answer for a generic implementation that doesn't try to access the first element in an empty vectors.

这篇关于c ++向量&lt; char&gt;和插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆