Simplify std::string construction involving concatenating integers in C++
问题 Looking for a more elegant shortcut to the following: for (int i=1; i<=maxNum; i++) { std::ostringstream s; s << i; std::string group1 = "group1_" + s.str(); std::string group2 = "group2_" + s.str(); . . . val = conf->read(group1.c_str()); . . . } Can anyone think of an elegant way like: conf->read({SOMEMACRO or function}("group1_", i)); Can this be done in place with a built-in C++ facility? Btw, boost is not an option. 回答1: Why not something like: inline std::string construct_group_id(int n