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 207 views
3 answers 266 views
1 answer 87 views
87 views asked Dec 23, 2024 by avibootz
3 answers 311 views
1 answer 85 views
2 answers 226 views
1 answer 199 views
199 views asked Feb 1, 2022 by avibootz
...