【发布时间】:2019-11-22 15:51:36
【问题描述】:
是否可以“轻松”将变量添加到 c++ 字符串?
我想要类似的行为
printf("integer %d", i);
但在字符串中,特别是在抛出这样的异常时:
int i = 0;
throw std::logic_error("value %i is incorrect");
应该和
一样std::string ans = "value ";
ans.append(std::atoi(i));
ans.append(" is incorrect");
throw std::logic_error(ans);
【问题讨论】: