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 310 views
1 answer 198 views
3 answers 266 views
1 answer 189 views
1 answer 225 views
1 answer 186 views
1 answer 189 views
...