How can the number n = 10 Add with letters aa (this is an example)? To get aa10 output at the end

  • string s = "aa"s+to_string(10); - Harry
  • one
    just: cout << "aa" << 10; - AR Hovsepyan

3 answers 3

In C ++ - for string - you can use simple + :

 string a = "aa"; int n = 10; string res = aa + to_string(n); 

In C, use sprintf or its safe counterparts:

 char res[20]; sprintf(res,"%s%d","aa",10); 
     std::ostringstream stream; // воодите что хотите stream << "aa" << 15 << 0.4 << "stream"; cout << stream.str(); 
       #include <string> //... int n=10; string s="aa"+to_string(n);