#include <iostream>
#include <string>
#include <cctype>
#include <assert.h>
using namespace std;
#define NDEBG
typedef bool (*cmpFcn)(const string &, const string &);
bool lengthCompare(const string &a, const string &b)
{
return a.size()>b.size()?1:0;
}
int main()
{
cmpFcn pf = lengthCompare;
cout<<"lengthCompare(hi,bye) "<<lengthCompare("hias","bye")<<endl;
cout<<"pf(hi,bye) "<<pf("hias","bye")<<endl;
cout<<"(*pf)(hi,hi) "<<(*pf)("hi","hi")<<endl;
}
本文详细介绍了如何在C++中实现字符串长度比较的自定义函数,并通过实例演示了其用法。
9498

被折叠的 条评论
为什么被折叠?



