How to repeat character N times in C++

1 Answer

0 votes
#include <iostream>

int main() {
    char ch = 'z';
    int N = 7;
    
    std::string s = std::string(N, ch);

    std::cout << s;
}
 
 
 
 
 
/*
run:
 
zzzzzzz
 
*/

 



answered Feb 21, 2022 by avibootz

Related questions

1 answer 200 views
3 answers 260 views
1 answer 80 views
80 views asked Dec 23, 2024 by avibootz
3 answers 308 views
1 answer 82 views
2 answers 224 views
1 answer 186 views
186 views asked Feb 1, 2022 by avibootz
...