C++坑系列,日志string拼接问题
·
❌ 错误的写法
std::string response = "LOG_OK: 日志已记录 [" + // const char[]
(level == LogLevel::DEBUG ? "DEBUG" : "INFO") + // const char*
"] " + log_content + "\n";
✅ 正确的写法
std::string response = std::string("LOG_OK: 日志已记录 [") + // 显式转换为std::string
(level == LogLevel::DEBUG ? "DEBUG" : "INFO") + // const char*
"] " + log_content + "\n";
更多推荐
所有评论(0)