How to concatenate a std::string and an int?
问题 I thought this would be really simple but it\'s presenting some difficulties. If I have std::string name = \"John\"; int age = 21; How do I combine them to get a single string \"John21\" ? 回答1: In alphabetical order: std::string name = "John"; int age = 21; std::string result; // 1. with Boost result = name + boost::lexical_cast<std::string>(age); // 2. with C++11 result = name + std::to_string(age); // 3. with FastFormat.Format fastformat::fmt(result, "{0}{1}", name, age); // 4. with