前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/*★ string search 前田 稔 ★*/
#include <stdio.h>
#include <string>
using namespace std;
int main()
{ string str= "redred black red white red gray";
int p;
for(p=0; (p=str.find("red",p))!=-1; p+=3)
printf("pos=%d\n", p);
return 0;
}
|
C:\DATA\Cpp\STL>StrSearch pos=0 pos=3 pos=13 pos=23 |
![]()
/*★ string replace 前田 稔 ★*/
#include <stdio.h>
#include <string>
using namespace std;
int main()
{ string str= "red black white red blue gray yellow";
int p;
for(p=0; (p=str.find("red",p))!=-1; p+=3)
str.replace(p,3,"purple");
printf("%s\n", str.data());
return 0;
}
|
C:\DATA\Cpp\STL>StrReplace purple black white purple blue gray yellow |
![]()