求指定字符在字符串中得位置
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char *s1="DBACEGF",*S2="ABCDEFG";
int n=strchr(s2,s1[0])-s2;
cout<<n<<endl;
system("pause")return 0;
}
编译时为什么出错??怎么样改??
[解决办法]
#include<iostream>#include<string.h>using namespace std;int main(){ char *s1="DBACEGF",*s2="ABCDEFG"; int n=strchr(s2,s1[0])-s2; cout<<n<<endl; system("pause"); return 0;}