gpt4 book ai didi

c++ - 修改日志类以接受字符串中的变量 - C++

转载 作者:行者123 更新时间:2023-11-30 04:33:27 26 4
gpt4 key购买 nike

我正在尝试修改我的日志类以接受我的字符串中的变量。比如我想输出一个区域有7个玩家。

这是我写入日志的函数:

void Log::writeSuccess(string text,...)
{
// Write the sucessfull operation to the logfile
logfile << "<---> " << text << endl;
}

这是我的调用代码:

int playernum = 7;

errorLog.writeSuccess("There are %i players in the area", playernum);

它只是最终输出到文件:该区域有 %i 个玩家

有什么办法可以解决这个问题吗?

最佳答案

我想知道你的程序究竟是如何编译的?!您使用 2 个参数调用 writeSuccess,而它被声明为仅采用一个参数。

你应该看看boost format

关于c++ - 修改日志类以接受字符串中的变量 - C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6843531/

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