gpt4 book ai didi

c++ - 运行 boost 的 io 服务时无法计算字符串

转载 作者:行者123 更新时间:2023-11-30 01:42:04 25 4
gpt4 key购买 nike

我有一些简单的代码:

#include <iostream>
#include <string>
int main() {
boost::asio::io_service ioservice;
TCPServer server(ioservice);
std::cout << "hello world";
ioservice.run();
}

我计算出上面的 hello world 字符串。虽然当我调用 service.run() 时,我的终端上没有输出字符串。当我删除最后一个调用表达式时,可以看到一个输出。让我烦恼的是,我在通话前 cout 并且没有输出任何内容。即使在我的 TCP 服务器上定义的处理程序上,cout 似乎也不可用。那么人们在使用 Boost Asio 时如何登录到标准输出呢?

最佳答案

您在输入 .run() 之前没有刷新流,因此您的信息仍位于缓冲区中。

使用 std::cout << std::flush (或 std::cout << std::endl 也包括换行符)。

关于c++ - 运行 boost 的 io 服务时无法计算字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40175617/

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