首页 > 其他 > 详细

String Replace 1.0

时间:2019-05-27 22:49:36      阅读:167      评论:0      收藏:0      [点我收藏+]

main.cpp

 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;
 5 
 6 string & replace_all ( string & str, const string & old_value, const string & new_value ) {
 7     while ( true ) {
 8         string::size_type pos ( 0 );
 9         if ( ( pos = str.find ( old_value ) ) != string::npos )
10             str.replace ( pos, old_value.length(), new_value );
11         else
12             break;
13     }
14     return str;
15 }
16 
17 int main ( int argc, char* argv[] ) {
18     string    s1    = argv[1];
19     string    s2    = argv[2];
20     string    s3    = argv[3];
21     cout << replace_all ( s3, s1, s2 ) << endl;
22     return 0;
23 }

技术分享图片

附件1

String Replace 1.0

原文:https://www.cnblogs.com/rms365/p/10934006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!