c++ add int to string code example
Example 1: c++ int to string
#include <string>
using namespace std;
int iIntAsInt = 658;
string sIntAsString = to_string(iIntAsInt);
Example 2: how to convert int to string c++
#include <iostream>
#include<string>
using namespace std;
int main()
{
int i=11;
string str= to_string(i);
cout<<"string value of integer i is :"<<str<<"\n";
return 0;
}
Example 3: convert a int to string c++
#include <iostream>
#include<string>
using namespace std;
int main()
{
int i = 11;
float f = 12.3;
string str = to_string(i);
strinf fstr = to_string(f);
}
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);
Example 5: how to convert int to string c++
#include <iostream>
#include <boost/lexical_cast.hpp>
using namespace std;
int main()
{
int i=11;
string str = boost::lexical_cast<string>(i);
cout<<"string value of integer i is :"<<str<<"\n";
}