【发布时间】:2011-05-12 18:33:56
【问题描述】:
有没有更好/更快的方法来创建从字符串 (const char *) 和数字 (int) 创建的字符串 (std 或 (const) char *),例如
动画0,动画1,动画2 ...动画99
比这个?
注意:不必使用 std,因为 hasValueForKey 接受 const char *
std::stringstream strIter("animation0");
int i = 0;
while (hasValueForKey(strIter.str().c_str())) {
// do some stuff
++i;
strIter.str(std::string());
strIter << "animation" << i;
}
谢谢
【问题讨论】:
-
您已经拥有了可能是最好、最安全的方法(尽管也许您可以跳过一个步骤并将 strIter 初始化为“动画”而不是空字符串)。