특정 문자열 변경 replace

jjuiddong
Jjuiddong (토론 | 기여) 사용자의 2013년 5월 19일 (일) 20:29 판

(비교) ← 이전 판 | 최신판 (비교) | 다음 판 → (비교)
이동: 둘러보기, 찾기
include <iostream>
using namespace std;
void ReplaceAll (string& strSrc, const string& strFind, const string& strDest)
{
    size_t j;
    while ((j = strSrc.find(strFind)) != string::npos)
        strSrc.replace(j, strFind.length(), strDest);
} 

int main (int argc, char** argv)
{
    string strSrc     = "this is test and this is are";
    string strFind    = "this";
    string strReplace = "that";
  
    cout << "Before :" << strSrc.c_str() << endl;
    ReplaceAll ( strSrc, strFind, strReplace );
    cout << "After :" << strSrc.c_str() << endl;

    return 0;
}
개인 도구
이름공간

변수
행위
둘러보기
도구모음