How to concatenate (repeat) a character N times into a string in C++

1 Answer

0 votes
#include <iostream>

int main() {
   char ch = 'w';
   
   int n = 4;
   
   std::string s = std::string(n, ch);
   
   std::cout << s;
   
   return 0;
}



/*
run:

wwww

*/

 



answered Jun 29, 2020 by avibootz

Related questions

3 answers 489 views
1 answer 276 views
3 answers 424 views
1 answer 274 views
1 answer 300 views
1 answer 278 views
1 answer 271 views
...