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 495 views
1 answer 281 views
3 answers 433 views
1 answer 279 views
1 answer 308 views
1 answer 283 views
1 answer 277 views
...