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

我设计了一个函数,目的是找出这个字符串中最大的那个字母,结果报错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;
}


Leo_clip
浏览 1676回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP