首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

求指定字符在字符串中得位置解决方案

2012-03-26 
求指定字符在字符串中得位置#includeiostream#includestring.husing namespace stdint main(){char *

求指定字符在字符串中得位置
#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;
}

编译时为什么出错??怎么样改??

[解决办法]

C/C++ code
#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;} 

热点排行