gpt4 book ai didi

用于套接字的 C++ 迭代器外观

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:13:05 25 4
gpt4 key购买 nike

我想知道是否有围绕套接字的 C++ 迭代器外观的良好实现(库)。我已经浏览了 Boost Iterator 库和 ASIO,但似乎找不到任何东西。开源解决方案会很棒!

我正在寻找以下用例的解决方案:

int socket_handler = 0;

socket_iterator it(socket_handler);
socket_iterator end;

//read mode 1:
while (it != end)
{
char c = *it;
.
.
++it;
}

//read mode 2:
while (it != end)
{
std::string s = *it;
.
.
++it;
}

//write mode 1:
unsigned char c = 0;
while (c < 100)
{
*it = c++;
.
.
++it;
}

//write mode 2:
std::sttring s = "abc";
for (unsigned int i = 0; i < 10; ++i)
{
*it = s;
.
.
++it;
}

注意:它==结束,当连接断开时。

最佳答案

@Gerdiner,Boost.Asio 是赢家。关于您的 istream_iterator,请检查以下内容:

boost::asio::streambuf myBuffer;
std::string myString;

// Convert streambuf to std::string
std::istream(&myBuffer) >> myString;

然而,使用 ASIO,您将不需要迭代器。请参阅以下异步客户端作为起点。

Async HTTP Client

关于用于套接字的 C++ 迭代器外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6091460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com