为了账号安全,请及时绑定邮箱和手机立即绑定

c++用指针比较字符串大小的问题

c++用指针比较字符串大小的问题

C C++
Leo_clip 2017-03-21 21:05:09
我设计了一个函数,目的是找出这个字符串中最大的那个字母,结果报错cannot convert 'bool' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)',求解该如修改函数#include<iostream> #include<cstring> using namespace std; template<class T> T max(T a[],int n) { T max=a[0]; for(int i=0;i<=n;i++) { for(int j=i+1;j<=n-1;j++) { if(a[i]<a[j]) { max=a[j]; } } } return max; } // char* max(char* p,int n) { char* max; char* p2; for(p;p<=p+n;p++) { for(p2=p+1;p2<=p+n-1;p2++) { if(strcmp(*p<*p2)) max=p2; } } return max; }  int main() { int a[5]={1,2,3,4,5}; cout<<max(a,5); char b[5]="abcd"; char *p=b; cout<<max(p,5); return 0; }
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1670 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信