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 307 views
1 answer 194 views
3 answers 260 views
1 answer 79 views
79 views asked Dec 23, 2024 by avibootz
1 answer 181 views
1 answer 217 views
1 answer 178 views
...