concatenate int to string c++ code example
Example 1: change int to string cpp
#include <string>
std::string s = std::to_string(42);
Example 2: c++ int to string
#include <string>
using namespace std;
int iIntAsInt = 658;
string sIntAsString = to_string(iIntAsInt);
Example 3: c++ int to string
#include <string>
int iIntAsInt = 658;
std::string sIntAsString = to_string(iIntAsInt);
#include <sstream>
#include <string>
int iYourInt = 5;
std::stringstream ssYourInt_AsStream << iYourInt;
std::string sYourInt_AsString = ssYourInt_AsStream.str();
Example 4: int and string concatination cp[
std::string name = "John";
int age = 21;
std::string result;
result = name + boost::lexical_cast<std::string>(age);
result = name + std::to_string(age);
fastformat::fmt(result, "{0}{1}", name, age);
fastformat::write(result, name, age);
result = fmt::format("{}{}", name, age);
std::stringstream sstm;
sstm << name << age;
result = sstm.str();
char numstr[21];
result = name + itoa(age, numstr, 10);
char numstr[21];
sprintf(numstr, "%d", age);
result = name + numstr;
char numstr[21];
result = name + stlsoft::integer_to_string(numstr, 21, age);
result = name + winstl::int_to_string(age);
result = name + Poco::NumberFormatter().format(age);