当 boost 的 io 服务正在运行时,无法执行字符串
Cannot cout string when boost's io service is running
我有一些简单的代码:
#include <iostream>
#include <string>
int main() {
boost::asio::io_service ioservice;
TCPServer server(ioservice);
std::cout << "hello world";
ioservice.run();
}
我计算上面的hello world字符串。虽然字符串没有被输出到我的终端,当我调用service.run()
。当我删除最后一个调用表达式时,可以看到一个输出。令我烦恼的是,我在调用之前进行计数,但没有任何输出。而且,即使在我的TCP服务器上定义的处理程序上,cout似乎也不可用。那么人们在使用Boost Asio时如何登录stdout呢?
您在进入.run()
之前没有刷新流,因此您的信息仍然位于缓冲区中。
使用std::cout << std::flush
(或std::cout << std::endl
也包括换行符)
相关文章:
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使字符串出现在编译的二进制可执行文件的开头?
- 如何执行不区分大小写的字符串比较?
- C++ - 使用用户输入的字符串数据检查结构字符串数据(无限执行 while 循环)
- readAll() 或 readAllStandardOutput() 在执行之前也返回一个空字符串
- 如何在没有外部库的情况下使用C++03约束执行基于正则表达式的字符串操作
- 如何在C++中对静态缓冲区执行字符串格式化?
- C++ - 查找函数无法在子字符串上执行
- 如何在 Python 或 C++ 中执行任意字符串?
- 是否有用于执行反向字符串拆分器的开箱即用功能?
- 如何使此函数使用 getline 读取字符串并使用 int 执行相同的行为?
- 如何对字符串作为指针执行大写转换
- 代码问题将字符串转换为图表执行
- QProcess::执行环境变量扩展字符串
- 如何使用 Win32 WCHAR 执行字符串操作
- 在执行字符串时更改字符会使程序崩溃
- 视觉 建议在C++中执行字符串分配什么?
- 我如何在c++中执行字符串作为shell脚本
- 当 boost 的 io 服务正在运行时,无法执行字符串
- 执行字符串分配时,C++程序崩溃