replace_if(beg,end,op,val)函数还是有时候有点作用的我觉得...
虽然不怎么好用, 如果是每个值都要经过特定的变换才能得到正确答案的话,,,其实可以用for_each()函数遍历然后每个做运算的
而上面的那个函数值是用作符合一定特征的所有的个体都发生变化的情况...
注意replace() 中间是需要4个参数的.
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <iostream>
- #include <algorithm>
- #include <time.h>
- using namespace std;
- bool op(char a)
- {
- if(a<='z'&&a>='a')
- return 1;
- else return 0;
- }
- bool visit(char a)
- {
- cout << a << " ";
- return 1;
- }
- int main()
- {
- char str[100];
- scanf("%s",str);
- int n=strlen(str);
- replace_if(str,str+n,op,'A');
- for_each(str,str+n,visit);
- return 0;
- }
C++中STL对string进行trim,split,replace操作
(2012-05-25 09:56:12) #include <iostream>
#include <vector>
using namespace std;
namespace strtool
{
string trim(const string& str)
{
}
int split(const string& str, vector<string>& ret_, string sep = ",")
{
}
string replace(const string& str, const string& src, const string& dest)
{
}
}
int main(int argc, char* argv[])
{
}