[stirng] 062. 문자열 일부 교체하기 ( replace )

jychan99·2021년 11월 8일
0
 #include <iostream>

#include <string>

using namespace std;



int main()

{

	string sentence = "i like coding";

	string find_str = "coding";

	string replace_str = "history";



	//문자열을 교체할때 replace함수를 쓴다.

	//문자열.replace(교체하고 싶은 단어, 교체하고 싶은 단어의 길이, 교체할 문자);

	sentence.replace(sentence.find(find_str), find_str.length(), replace_str);



	cout << sentence << endl;



	return 0;

}
profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐍

0개의 댓글

관련 채용 정보