stl的string功能强大,但是比较慢,在比赛中字符数组用的还是比较多,所以这里贴上三个功能强大,但是不常用的字符串函数
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <list>
- #include <string>
- using namespace std;
- main()
- {
- char s[50]="hello world, and everything goes fine",
- d[20]=", ", t[20]="ad", *p;
- int pos;
- p = strpbrk(s,t); // find the positon of fist character in s which is also in t
- printf("%s/n/n", p);
- pos = strcspn(s,t); // find the index(int) of first character in s which is also in t
- printf("%s/n/n", s+pos);
- p = strtok(s,d); // use the characters of d to divide s
- while(p) // hint: it's not *p
- {
- puts(p);
- p = strtok(NULL,d);
- }
- system("pause");
- return 0;
- }