#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
string str;
srand( (unsigned)time(0) );
string alpa[26]={"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z"};
int cstr;
int calpa;
cout << "아래에 한 줄을 입력하세세요 (exit를 입력하면 종료합니다.)"<< endl;
while(1){
cout << ">> ";
getline(cin,str);
if(str=="exit")break;
cstr=rand()%str.size();
calpa=rand()%26;
str.replace(cstr,1,alpa[calpa]);
cout <<str<<endl;
}
return 0;
}
설명 >
replace (cstr, 1, alpa[alpa] ) ;
기존 문자열의 pos 부터 count 개 만큼, 혹은 first 부터 last 까지를 string_view 로 변환 가능한 타입 t 로 치환한다
calpa =rand() %26;
alpha 배열을 만들어서 alpa[calpa] 로 이용한다
'언어 > C++' 카테고리의 다른 글
4장 5,6번 - 동적할당으로 원 반지름, 면적 구하기 (0) | 2019.11.21 |
---|---|
4장4번 - 문장 거꾸로 출력하기 (0) | 2019.11.21 |
4장 2번 - 가장 큰 수 찾기 (0) | 2019.11.21 |
up & down 게임 만들기 ! (0) | 2019.11.20 |
끝말잇기 게임 만들기 ! (0) | 2019.11.20 |