(EDIT: this is an answer to the question before the edit that mentioned QString. For QString, see the newer answer)
This can be done as a very similar one-liner using C++11:
int i = 5;
std::string directory = ":/karim/pic" + std::to_string(i) + ".jpg";
Test: https://ideone.com/jIAxE
With older compilers, it can be substituted with Boost:
int i = 5;
std::string directory = ":/karim/pic" + boost::lexical_cast<std::string>(i) + ".jpg";
Test: https://ideone.com/LFtt7
But the classic way to do it is with a string stream object.
int i = 5;
std::ostringstream oss;
oss << ":/karim/pic" << i << ".jpg";
std::string directory = oss.str();
Test: https://ideone.com/6QVPv
qt
, the answers in the "duplicate" don't provide that.QString dir = ":/karim/pic" + QString::number(i) + ".jpg";
std::string
, if you ever need aQString
and you have anstd::string
, use this function