ch를 count만큼 반복하여 문자열을 초기화한다.std::string str(5, 'a');는 "aaaaa"라는 문자열을 생성한다.예시
#include <iostream>
#include <string>
int main() {
// 문자 'x'를 10번 반복한 문자열 생성
std::string repeatedStr(10, 'x');
// 결과 출력
std::cout << "생성된 문자열: " << repeatedStr << std::endl;
// 다른 예제: '*'를 5번 반복
std::string stars(5, '*');
std::cout << "별 모양 문자열: " << stars << std::endl;
return 0;
}
출력
생성된 문자열: xxxxxxxxxx
별 모양 문자열: *****