<分区>
在工作中,我们必须用函数 void output(std::string)
替换 iostream :
std::cout << "This is some output." << '\n';
<--Old--
--New-->
output("This is some output");
当然,我有很多代码将字符串和 int 组合在一起,而且我已经找到了解决此问题的一种可能方法:
int some_value = 5
std::cout << "Some value: " << some_value << '\n';
<--Old--
--New-->
int some_value = 5;
std::stringstream tmp_stream;
tmp_stream << "Some value: " << some_value << '\n';
output(tmp_stream.str());
但我不太喜欢这个解决方案,因为它引入了另外两行代码和一个额外的一次性变量。您是否知道其他更优雅的解决方案?