如果我有一个函数myfunc(const char *x, int y)
和std::string
变量mystring
,我可以叫myfunc()
喜欢myfunc((mystring + "string constant").c_str(), 4)
?如果没有,什么是最好的方法呢?
不,您不应该这样称呼它。
myfunc((mystring + "string constant").c_str(), 4)
如临时创建要持有mystring + "string constant"
。当您c_str
在该临时目录上申请时,它将返回该字符串的内部句柄。因此,如果您得到不想要的结果,请不要感到惊讶。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句