receiver->get_identifier().c_str()
返回const char*
,而不是std::string
,因此无法插入operator+
(其中一个参数必须为std::string
)。删除c_str()
并最后转换为std::string::c_str()
应该可以解决问题
fopen(("client." + receiver->get_identifier() + ".vol").c_str(), "a+");
这是因为您将有一个const char*
加号std::string
,并且operator+
可以使用。
如果您可能想知道为什么不能为operator+
for定义for const char*
,那是因为C ++不允许对基本类型进行运算符重载。至少一个参数必须是用户定义的类型。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句