#pragma warning(disable:4786)
#include
#include
#include
#include
using namespace std;
/* 从小到大排序 */
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
typedef map MYDATAMAP;
typedef MYDATAMAP::iterator Itermydata;
int main(int argc, char* argv[])
{
MYDATAMAP mydata;
mydata.insert(Itermydata::value_type("3",9));
mydata.insert(Itermydata::value_type("4",9));
mydata.insert(Itermydata::value_type("1",9));
mydata.insert(Itermydata::value_type("2",9));
Itermydata begin = mydata.begin();
for(; begin != mydata.end(); ++begin)
{
cout<<"Key: " << begin->first
<<" Value: " << begin->second <
}
mydata.clear();
return 0;
}
结果输出为:
Key: 1 Value: 9
Key: 2 Value: 9
Key: 3 Value: 9
Key: 4 Value: 9
3COME考试频道为您精心整理,希望对您有所帮助,更多信息在http://www.reader8.com/exam/