How do you append an int to a string in C++? [duplicate]

With C++11, you can write:

#include <string>     // to use std::string, std::to_string() and "+" operator acting on strings 

int i = 4;
std::string text = "Player ";
text += std::to_string(i);

Leave a Comment