How to create a string with a repeated character N times in C++

1 Answer

0 votes
#include <iostream>
 
int main() {
    char ch = '*';
    int N = 10;
     
    std::string s = std::string(N, ch);
 
    std::cout << s;
}

  
  
/*
run:

**********
  
*/

 



answered Jul 27, 2025 by avibootz
...