69,336
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<cstring>
using namespace std;
template<class T> int comp(T v1, T v2)
{
if(v1 > v2)
return 1;
if(v1 == v2)
return 0;
return -1;
}
template<>int comp<char*>(char*x,char*y){
if(!strcmp(x,y)) return 0;
else if(strcmp(x,y)>0)return 1;
else return -1;
}
int main()
{
char ch[]="abc";
char st[]="abcde";
cout<<comp(ch,st)<<endl;
system("pause");
return 0;
}
template<class T> int compare(T v1, T v2)
{
if(v1 > v2)
return 1;
if(v1 == v2)
return 0;
return -1;
}