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

一个C++有关问题 不在乎大小写比较字符串

2013-01-08 
求助一个C++问题 不在乎大小写比较字符串程序主要来自《C++ 标准程序库》不在乎大小比较字符串下面是我写的

求助一个C++问题 不在乎大小写比较字符串
程序主要来自《C++ 标准程序库》
不在乎大小比较字符串  
下面是我写的一个程序 


#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>
#include <set>
#include <string>
using namespace std;

class cmp
{
public:
bool operator()(const string &a, const string &b)
{
if( _stricmp(a.c_str(),b.c_str()) )
return 1;
else
return 0;
return 0;
}
};

int main()
{
typedef multimap<string,string> MulMap;
MulMap mmap;
mmap.insert(make_pair("Deutschland","Germany"));
mmap.insert(make_pair("deutsch","German"));
mmap.insert(make_pair("Haken","snag"));
mmap.insert(make_pair("arbeiten","work"));
mmap.insert(make_pair("Hund","dog"));
mmap.insert(make_pair("gehen","go"));
mmap.insert(make_pair("Unternehmen","enterprise"));
mmap.insert(make_pair("unternehmen","undertake"));
mmap.insert(make_pair("gehen","walk"));
mmap.insert(make_pair("Bestatter","undertaker"));


MulMap::iterator pos1;
for(pos1 = mmap.begin(); pos1 != mmap.end(); ++pos1)
cout << pos1->first << '\t' << pos1->second << endl;

cout << endl << endl;

multimap<string,string,cmp> temp(mmap.begin(),mmap.end());
multimap<string,string,cmp>::iterator pos2;
for(pos2 = temp.begin(); pos2 != temp.end(); ++pos2)
cout << pos2->first << '\t' << pos2->second << endl;


return 0;
}



程序编译通过 运行时会报错 求解哦~~~
[解决办法]
class cmp
{
public:
    bool operator()(const string &a, const string &b)
    {
        if( _stricmp(a.c_str(),b.c_str()) > 0 )
            return true;
        else
            return false;
        //return false;
    }
};
[解决办法]
自己去看下_stricmp的返回值是什么

热点排行