#include<iostream>
#include<cstring>
using namespace std;
int main(){
char str[] = "This is a sample string";
const char *pch;
pch = strchr(str, 's');
cout << pch;
while (pch!=0){
cout << pch - str + 1 << endl;
pch = strchr(pch+1, 's');
}
return 0;
}
运行结果:
s is a sample string4
7
11
18