P9 文件传输

为什么 TCP 是可靠的通信,服务端每一步都要有回复。 因为服务端可能没有 accept 或者可能忙于其他事情,bug 掉线等等。所以虽然 TCP 本身是可靠的,但是服务器可能是不可靠的。所以为了业务是正常的,就必须在服务端正常应答的情况下,才能继续。 读取文件使用 ifstream 操作 字符串拼接报错? 一般情况都是只有 char * 和 char * 拼接,才会报错。只要语句中有一个 string, 拼接就不会报错。 参考 实现文件传输功能

2023-09-20 · 1 min · 24 words · RamLife

c++ json 库 nlohmann 文件读写

需求 nlohmman 读写 json 配置文件. 解决 写文件 QString fileName = QFileDialog::getSaveFileName(this, tr("save config file"), "./voltage_", tr("Json (*.json)")); qDebug() << fileName << Qt::endl; if (fileName.isEmpty()) return; ofstream file(fileName.toStdString(), ios::out); json j; to_json(j, config_json); file << j << std::endl; 读文件 QString file_name = QFileDialog::getOpenFileName(this, tr("load config file"), "./voltage_", tr("Json (*.json)")); qDebug() << file_name << Qt::endl; if (file_name.isEmpty()) return; ifstream file(file_name.toStdString(), ios::in); json j = json::parse(file); 参考 nlohmann/json 的主要用法 【C++ JSON 开源库】nlohmann入门使用总结 nlohmann/json...

2023-06-26 · 1 min · 72 words · RamLife