自己编写,一费时,二担心效率
C++Builder有这样的实现方法吗?
麻烦给出代码示例!!
11 个解决方案
#1
有的STL实现中有hash table,找找STLPort.
#2
STL中的map不是现成的吗?比之Java那是强多了,而且是类型安全的,用起来也非常方便。
#3
如何在C++Builder中使用STL呢?内带吗?
包含那个头文件?
包含那个头文件?
#4
#include <map.h>
using namespace std;
map<String,TEdit*> map1;
map1["Edit1"]=Edit1;
map1["Edit2"]=Edit2;
map1["Edit1"]->Text="aaaaaa";
map1["Edit2"]->Text="bbbbbb";
using namespace std;
map<String,TEdit*> map1;
map1["Edit1"]=Edit1;
map1["Edit2"]=Edit2;
map1["Edit1"]->Text="aaaaaa";
map1["Edit2"]->Text="bbbbbb";
#5
还是不行啊,谁能给个具体点的例子!
我这样用在Tools.h中
#include <map.h>
using namespace std;
class Tools
{
public:
typedef map<String, String> StringMap;
static StringMap keymap;
...
然后cpp文件中
...
keymap.insert("UPTIME","10");
...
编译后,却在一个_tree.h文件中报错,它根本是CB自带的文件
[C++ Error] _tree.h(395): E2285 Could not find a match for '_Rb_tree<AnsiString,pair<const AnsiString,AnsiString>,_Select1st<pair<const AnsiString,AnsiString> >,less<AnsiString>,allocator<pair<const AnsiString,AnsiString> > >::insert_unique(char)'
谁知道怎么回事?麻烦给个map的详细例子吧!!!
我这样用在Tools.h中
#include <map.h>
using namespace std;
class Tools
{
public:
typedef map<String, String> StringMap;
static StringMap keymap;
...
然后cpp文件中
...
keymap.insert("UPTIME","10");
...
编译后,却在一个_tree.h文件中报错,它根本是CB自带的文件
[C++ Error] _tree.h(395): E2285 Could not find a match for '_Rb_tree<AnsiString,pair<const AnsiString,AnsiString>,_Select1st<pair<const AnsiString,AnsiString> >,less<AnsiString>,allocator<pair<const AnsiString,AnsiString> > >::insert_unique(char)'
谁知道怎么回事?麻烦给个map的详细例子吧!!!
#6
up
#7
std::map
// map_map.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
typedef pair <int, int> Int_Pair;
map <int, int>::iterator m1_Iter, m3_Iter, m4_Iter, m5_Iter, m6_Iter;
map <int, int, greater<int> >::iterator m2_Iter;
// Create an empty map m0 of key type integer
map <int, int> m0;
// Create an empty map m1 with the key comparison
// function of less than, then insert 4 elements
map <int, int, less<int> > m1;
m1.insert( Int_Pair( 1, 10 ) );
m1.insert( Int_Pair( 2, 20 ) );
m1.insert( Int_Pair( 3, 30 ) );
m1.insert( Int_Pair( 4, 40 ) );
// Create an empty map m2 with the key comparison
// function of geater than, then insert 2 elements
map <int, int, greater<int> > m2;
m2.insert( Int_Pair( 1, 10 ) );
m2.insert( Int_Pair( 2, 20 ) );
// Create a map m3 with the
// allocator of map m1
map <int, int>::allocator_type m1_Alloc;
m1_Alloc = m1.get_allocator( );
map <int, int> m3( less<int>( ), m1_Alloc );
m3.insert( Int_Pair( 3, 30 ) );
// Create a copy, map m4, of map m1
map <int, int> m4( m1 );
// Create a map m5 by copying the range m1[_First, _Last)
map <int, int>::const_iterator m1_bcIter, m1_ecIter;
m1_bcIter = m1.begin( );
m1_ecIter = m1.begin( );
m1_ecIter++;
m1_ecIter++;
map <int, int> m5(m1_bcIter, m1_ecIter);
// Create a map m6 by copying the range m4[_First, _Last)
// and with the allocator of map m2
map <int, int>::allocator_type m2_Alloc;
m2_Alloc = m2.get_allocator( );
map <int, int> m6( m4.begin( ), ++m4.begin( ), less<int>( ), m2_Alloc);
cout << "m1 =";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << endl;
cout << "m2 =";
for ( m2_Iter = m2.begin( ); m2_Iter != m2.end( ); m2_Iter++ )
cout << " " << m2_Iter -> second;
cout << endl;
cout << "m3 =";
for ( m3_Iter = m3.begin( ); m3_Iter != m3.end( ); m3_Iter++ )
cout << " " << m3_Iter -> second;
cout << endl;
cout << "m4 =";
for ( m4_Iter = m4.begin( ); m4_Iter != m4.end( ); m4_Iter++ )
cout << " " << m4_Iter -> second;
cout << endl;
cout << "m5 =";
for ( m5_Iter = m5.begin( ); m5_Iter != m5.end( ); m5_Iter++ )
cout << " " << m5_Iter -> second;
cout << endl;
cout << "m6 =";
for ( m6_Iter = m6.begin( ); m6_Iter != m6.end( ); m6_Iter++ )
cout << " " << m6_Iter -> second;
cout << endl;
}
Output
m1 = 10 20 30 40
m2 = 20 10
m3 = 30
m4 = 10 20 30 40
m5 = 10 20
m6 = 10
// map_map.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
typedef pair <int, int> Int_Pair;
map <int, int>::iterator m1_Iter, m3_Iter, m4_Iter, m5_Iter, m6_Iter;
map <int, int, greater<int> >::iterator m2_Iter;
// Create an empty map m0 of key type integer
map <int, int> m0;
// Create an empty map m1 with the key comparison
// function of less than, then insert 4 elements
map <int, int, less<int> > m1;
m1.insert( Int_Pair( 1, 10 ) );
m1.insert( Int_Pair( 2, 20 ) );
m1.insert( Int_Pair( 3, 30 ) );
m1.insert( Int_Pair( 4, 40 ) );
// Create an empty map m2 with the key comparison
// function of geater than, then insert 2 elements
map <int, int, greater<int> > m2;
m2.insert( Int_Pair( 1, 10 ) );
m2.insert( Int_Pair( 2, 20 ) );
// Create a map m3 with the
// allocator of map m1
map <int, int>::allocator_type m1_Alloc;
m1_Alloc = m1.get_allocator( );
map <int, int> m3( less<int>( ), m1_Alloc );
m3.insert( Int_Pair( 3, 30 ) );
// Create a copy, map m4, of map m1
map <int, int> m4( m1 );
// Create a map m5 by copying the range m1[_First, _Last)
map <int, int>::const_iterator m1_bcIter, m1_ecIter;
m1_bcIter = m1.begin( );
m1_ecIter = m1.begin( );
m1_ecIter++;
m1_ecIter++;
map <int, int> m5(m1_bcIter, m1_ecIter);
// Create a map m6 by copying the range m4[_First, _Last)
// and with the allocator of map m2
map <int, int>::allocator_type m2_Alloc;
m2_Alloc = m2.get_allocator( );
map <int, int> m6( m4.begin( ), ++m4.begin( ), less<int>( ), m2_Alloc);
cout << "m1 =";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << endl;
cout << "m2 =";
for ( m2_Iter = m2.begin( ); m2_Iter != m2.end( ); m2_Iter++ )
cout << " " << m2_Iter -> second;
cout << endl;
cout << "m3 =";
for ( m3_Iter = m3.begin( ); m3_Iter != m3.end( ); m3_Iter++ )
cout << " " << m3_Iter -> second;
cout << endl;
cout << "m4 =";
for ( m4_Iter = m4.begin( ); m4_Iter != m4.end( ); m4_Iter++ )
cout << " " << m4_Iter -> second;
cout << endl;
cout << "m5 =";
for ( m5_Iter = m5.begin( ); m5_Iter != m5.end( ); m5_Iter++ )
cout << " " << m5_Iter -> second;
cout << endl;
cout << "m6 =";
for ( m6_Iter = m6.begin( ); m6_Iter != m6.end( ); m6_Iter++ )
cout << " " << m6_Iter -> second;
cout << endl;
}
Output
m1 = 10 20 30 40
m2 = 20 10
m3 = 30
m4 = 10 20 30 40
m5 = 10 20
m6 = 10
#8
map MembersSee Also
map Class | Thread Safety in the Standard C++ Library
Typedefs
allocator_type A type that represents the allocator class for the map object.
const_iterator A type that provides a bidirectional iterator that can read a const element in the map.
const_pointer A type that provides a pointer to a const element in a map.
const_reference A type that provides a reference to a const element stored in a map for reading and performing const operations.
const_reverse_iterator A type that provides a bidirectional iterator that can read any const element in the map.
difference_type A signed integer type that can be used to represent the number of elements of a map in a range between elements pointed to by iterators.
iterator A type that provides a bidirectional iterator that can read or modify any element in a map.
key_compare A type that provides a function object that can compare two sort keys to determine the relative order of two elements in the map.
key_type A type that describes the sort key object which constitutes each element of the map.
mapped_type A type that represents the data type stored in a map.
pointer A type that provides a pointer to a const element in a map.
reference A type that provides a reference to an element stored in a map.
reverse_iterator A type that provides a bidirectional iterator that can read or modify an element in a reversed map.
size_type An unsigned integer type that can represent the number of elements in a map
value_type A type that provides a function object that can compare two elements as sort keys to determine their relative order in the map.
Member Functions
begin Returns an iterator addressing the first element in the map.
clear Erases all the elements of a map.
count Returns the number of elements in a map whose key matches a parameter-specified key.
empty Tests if a map is empty.
end Returns an iterator that addresses the location succeeding the last element in a map.
equal_range Returns an iterator that addresses the location succeeding the last element in a map.
erase Removes an element or a range of elements in a map from specified positions
find Returns an iterator addressing the location of an element in a map that has a key equivalent to a specified key.
get_allocator Returns a copy of the allocator object used to construct the map.
insert Inserts an element or a range of elements into the map at a specified position.
key_comp Retrieves a copy of the comparison object used to order keys in a map.
lower_bound Returns an iterator to the first element in a map that with a key value that is equal to or greater than that of a specified key.
map Constructs a list of a specific size or with elements of a specific value or with a specific allocator or as a copy of some other map.
max_size Returns the maximum length of the map.
rbegin Returns an iterator addressing the first element in a reversed map.
rend Returns an iterator that addresses the location succeeding the last element in a reversed map.
size Returns the number of elements in the map.
swap Exchanges the elements of two maps.
upper_bound Returns an iterator to the first element in a map that with a key value that is greater than that of a specified key.
value_comp Retrieves a copy of the comparison object used to order element values in a map.
Operators
operator[] Inserts an element into a map with a specified key value.
map Class | Thread Safety in the Standard C++ Library
Typedefs
allocator_type A type that represents the allocator class for the map object.
const_iterator A type that provides a bidirectional iterator that can read a const element in the map.
const_pointer A type that provides a pointer to a const element in a map.
const_reference A type that provides a reference to a const element stored in a map for reading and performing const operations.
const_reverse_iterator A type that provides a bidirectional iterator that can read any const element in the map.
difference_type A signed integer type that can be used to represent the number of elements of a map in a range between elements pointed to by iterators.
iterator A type that provides a bidirectional iterator that can read or modify any element in a map.
key_compare A type that provides a function object that can compare two sort keys to determine the relative order of two elements in the map.
key_type A type that describes the sort key object which constitutes each element of the map.
mapped_type A type that represents the data type stored in a map.
pointer A type that provides a pointer to a const element in a map.
reference A type that provides a reference to an element stored in a map.
reverse_iterator A type that provides a bidirectional iterator that can read or modify an element in a reversed map.
size_type An unsigned integer type that can represent the number of elements in a map
value_type A type that provides a function object that can compare two elements as sort keys to determine their relative order in the map.
Member Functions
begin Returns an iterator addressing the first element in the map.
clear Erases all the elements of a map.
count Returns the number of elements in a map whose key matches a parameter-specified key.
empty Tests if a map is empty.
end Returns an iterator that addresses the location succeeding the last element in a map.
equal_range Returns an iterator that addresses the location succeeding the last element in a map.
erase Removes an element or a range of elements in a map from specified positions
find Returns an iterator addressing the location of an element in a map that has a key equivalent to a specified key.
get_allocator Returns a copy of the allocator object used to construct the map.
insert Inserts an element or a range of elements into the map at a specified position.
key_comp Retrieves a copy of the comparison object used to order keys in a map.
lower_bound Returns an iterator to the first element in a map that with a key value that is equal to or greater than that of a specified key.
map Constructs a list of a specific size or with elements of a specific value or with a specific allocator or as a copy of some other map.
max_size Returns the maximum length of the map.
rbegin Returns an iterator addressing the first element in a reversed map.
rend Returns an iterator that addresses the location succeeding the last element in a reversed map.
size Returns the number of elements in the map.
swap Exchanges the elements of two maps.
upper_bound Returns an iterator to the first element in a map that with a key value that is greater than that of a specified key.
value_comp Retrieves a copy of the comparison object used to order element values in a map.
Operators
operator[] Inserts an element into a map with a specified key value.
#9
兄弟,找本C++的教科书看看,你的问题太基础了。推荐《C++程序设计语言(特别版)》,C++之父Bjarne Stroustrup博士写的,裘宗燕教授翻译。
#10
up
#11
回复:proton(落花有意,流水无情)
主要是insert时类型不匹配。可以这样:
.h文件中:typedef map<xxx, yyy>::value_type valType;
.cpp文件中:yourmap.insert(valType(xxx_实际值,yyy_实际值));
主要是insert时类型不匹配。可以这样:
.h文件中:typedef map<xxx, yyy>::value_type valType;
.cpp文件中:yourmap.insert(valType(xxx_实际值,yyy_实际值));
#1
有的STL实现中有hash table,找找STLPort.
#2
STL中的map不是现成的吗?比之Java那是强多了,而且是类型安全的,用起来也非常方便。
#3
如何在C++Builder中使用STL呢?内带吗?
包含那个头文件?
包含那个头文件?
#4
#include <map.h>
using namespace std;
map<String,TEdit*> map1;
map1["Edit1"]=Edit1;
map1["Edit2"]=Edit2;
map1["Edit1"]->Text="aaaaaa";
map1["Edit2"]->Text="bbbbbb";
using namespace std;
map<String,TEdit*> map1;
map1["Edit1"]=Edit1;
map1["Edit2"]=Edit2;
map1["Edit1"]->Text="aaaaaa";
map1["Edit2"]->Text="bbbbbb";
#5
还是不行啊,谁能给个具体点的例子!
我这样用在Tools.h中
#include <map.h>
using namespace std;
class Tools
{
public:
typedef map<String, String> StringMap;
static StringMap keymap;
...
然后cpp文件中
...
keymap.insert("UPTIME","10");
...
编译后,却在一个_tree.h文件中报错,它根本是CB自带的文件
[C++ Error] _tree.h(395): E2285 Could not find a match for '_Rb_tree<AnsiString,pair<const AnsiString,AnsiString>,_Select1st<pair<const AnsiString,AnsiString> >,less<AnsiString>,allocator<pair<const AnsiString,AnsiString> > >::insert_unique(char)'
谁知道怎么回事?麻烦给个map的详细例子吧!!!
我这样用在Tools.h中
#include <map.h>
using namespace std;
class Tools
{
public:
typedef map<String, String> StringMap;
static StringMap keymap;
...
然后cpp文件中
...
keymap.insert("UPTIME","10");
...
编译后,却在一个_tree.h文件中报错,它根本是CB自带的文件
[C++ Error] _tree.h(395): E2285 Could not find a match for '_Rb_tree<AnsiString,pair<const AnsiString,AnsiString>,_Select1st<pair<const AnsiString,AnsiString> >,less<AnsiString>,allocator<pair<const AnsiString,AnsiString> > >::insert_unique(char)'
谁知道怎么回事?麻烦给个map的详细例子吧!!!
#6
up
#7
std::map
// map_map.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
typedef pair <int, int> Int_Pair;
map <int, int>::iterator m1_Iter, m3_Iter, m4_Iter, m5_Iter, m6_Iter;
map <int, int, greater<int> >::iterator m2_Iter;
// Create an empty map m0 of key type integer
map <int, int> m0;
// Create an empty map m1 with the key comparison
// function of less than, then insert 4 elements
map <int, int, less<int> > m1;
m1.insert( Int_Pair( 1, 10 ) );
m1.insert( Int_Pair( 2, 20 ) );
m1.insert( Int_Pair( 3, 30 ) );
m1.insert( Int_Pair( 4, 40 ) );
// Create an empty map m2 with the key comparison
// function of geater than, then insert 2 elements
map <int, int, greater<int> > m2;
m2.insert( Int_Pair( 1, 10 ) );
m2.insert( Int_Pair( 2, 20 ) );
// Create a map m3 with the
// allocator of map m1
map <int, int>::allocator_type m1_Alloc;
m1_Alloc = m1.get_allocator( );
map <int, int> m3( less<int>( ), m1_Alloc );
m3.insert( Int_Pair( 3, 30 ) );
// Create a copy, map m4, of map m1
map <int, int> m4( m1 );
// Create a map m5 by copying the range m1[_First, _Last)
map <int, int>::const_iterator m1_bcIter, m1_ecIter;
m1_bcIter = m1.begin( );
m1_ecIter = m1.begin( );
m1_ecIter++;
m1_ecIter++;
map <int, int> m5(m1_bcIter, m1_ecIter);
// Create a map m6 by copying the range m4[_First, _Last)
// and with the allocator of map m2
map <int, int>::allocator_type m2_Alloc;
m2_Alloc = m2.get_allocator( );
map <int, int> m6( m4.begin( ), ++m4.begin( ), less<int>( ), m2_Alloc);
cout << "m1 =";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << endl;
cout << "m2 =";
for ( m2_Iter = m2.begin( ); m2_Iter != m2.end( ); m2_Iter++ )
cout << " " << m2_Iter -> second;
cout << endl;
cout << "m3 =";
for ( m3_Iter = m3.begin( ); m3_Iter != m3.end( ); m3_Iter++ )
cout << " " << m3_Iter -> second;
cout << endl;
cout << "m4 =";
for ( m4_Iter = m4.begin( ); m4_Iter != m4.end( ); m4_Iter++ )
cout << " " << m4_Iter -> second;
cout << endl;
cout << "m5 =";
for ( m5_Iter = m5.begin( ); m5_Iter != m5.end( ); m5_Iter++ )
cout << " " << m5_Iter -> second;
cout << endl;
cout << "m6 =";
for ( m6_Iter = m6.begin( ); m6_Iter != m6.end( ); m6_Iter++ )
cout << " " << m6_Iter -> second;
cout << endl;
}
Output
m1 = 10 20 30 40
m2 = 20 10
m3 = 30
m4 = 10 20 30 40
m5 = 10 20
m6 = 10
// map_map.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
typedef pair <int, int> Int_Pair;
map <int, int>::iterator m1_Iter, m3_Iter, m4_Iter, m5_Iter, m6_Iter;
map <int, int, greater<int> >::iterator m2_Iter;
// Create an empty map m0 of key type integer
map <int, int> m0;
// Create an empty map m1 with the key comparison
// function of less than, then insert 4 elements
map <int, int, less<int> > m1;
m1.insert( Int_Pair( 1, 10 ) );
m1.insert( Int_Pair( 2, 20 ) );
m1.insert( Int_Pair( 3, 30 ) );
m1.insert( Int_Pair( 4, 40 ) );
// Create an empty map m2 with the key comparison
// function of geater than, then insert 2 elements
map <int, int, greater<int> > m2;
m2.insert( Int_Pair( 1, 10 ) );
m2.insert( Int_Pair( 2, 20 ) );
// Create a map m3 with the
// allocator of map m1
map <int, int>::allocator_type m1_Alloc;
m1_Alloc = m1.get_allocator( );
map <int, int> m3( less<int>( ), m1_Alloc );
m3.insert( Int_Pair( 3, 30 ) );
// Create a copy, map m4, of map m1
map <int, int> m4( m1 );
// Create a map m5 by copying the range m1[_First, _Last)
map <int, int>::const_iterator m1_bcIter, m1_ecIter;
m1_bcIter = m1.begin( );
m1_ecIter = m1.begin( );
m1_ecIter++;
m1_ecIter++;
map <int, int> m5(m1_bcIter, m1_ecIter);
// Create a map m6 by copying the range m4[_First, _Last)
// and with the allocator of map m2
map <int, int>::allocator_type m2_Alloc;
m2_Alloc = m2.get_allocator( );
map <int, int> m6( m4.begin( ), ++m4.begin( ), less<int>( ), m2_Alloc);
cout << "m1 =";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << endl;
cout << "m2 =";
for ( m2_Iter = m2.begin( ); m2_Iter != m2.end( ); m2_Iter++ )
cout << " " << m2_Iter -> second;
cout << endl;
cout << "m3 =";
for ( m3_Iter = m3.begin( ); m3_Iter != m3.end( ); m3_Iter++ )
cout << " " << m3_Iter -> second;
cout << endl;
cout << "m4 =";
for ( m4_Iter = m4.begin( ); m4_Iter != m4.end( ); m4_Iter++ )
cout << " " << m4_Iter -> second;
cout << endl;
cout << "m5 =";
for ( m5_Iter = m5.begin( ); m5_Iter != m5.end( ); m5_Iter++ )
cout << " " << m5_Iter -> second;
cout << endl;
cout << "m6 =";
for ( m6_Iter = m6.begin( ); m6_Iter != m6.end( ); m6_Iter++ )
cout << " " << m6_Iter -> second;
cout << endl;
}
Output
m1 = 10 20 30 40
m2 = 20 10
m3 = 30
m4 = 10 20 30 40
m5 = 10 20
m6 = 10
#8
map MembersSee Also
map Class | Thread Safety in the Standard C++ Library
Typedefs
allocator_type A type that represents the allocator class for the map object.
const_iterator A type that provides a bidirectional iterator that can read a const element in the map.
const_pointer A type that provides a pointer to a const element in a map.
const_reference A type that provides a reference to a const element stored in a map for reading and performing const operations.
const_reverse_iterator A type that provides a bidirectional iterator that can read any const element in the map.
difference_type A signed integer type that can be used to represent the number of elements of a map in a range between elements pointed to by iterators.
iterator A type that provides a bidirectional iterator that can read or modify any element in a map.
key_compare A type that provides a function object that can compare two sort keys to determine the relative order of two elements in the map.
key_type A type that describes the sort key object which constitutes each element of the map.
mapped_type A type that represents the data type stored in a map.
pointer A type that provides a pointer to a const element in a map.
reference A type that provides a reference to an element stored in a map.
reverse_iterator A type that provides a bidirectional iterator that can read or modify an element in a reversed map.
size_type An unsigned integer type that can represent the number of elements in a map
value_type A type that provides a function object that can compare two elements as sort keys to determine their relative order in the map.
Member Functions
begin Returns an iterator addressing the first element in the map.
clear Erases all the elements of a map.
count Returns the number of elements in a map whose key matches a parameter-specified key.
empty Tests if a map is empty.
end Returns an iterator that addresses the location succeeding the last element in a map.
equal_range Returns an iterator that addresses the location succeeding the last element in a map.
erase Removes an element or a range of elements in a map from specified positions
find Returns an iterator addressing the location of an element in a map that has a key equivalent to a specified key.
get_allocator Returns a copy of the allocator object used to construct the map.
insert Inserts an element or a range of elements into the map at a specified position.
key_comp Retrieves a copy of the comparison object used to order keys in a map.
lower_bound Returns an iterator to the first element in a map that with a key value that is equal to or greater than that of a specified key.
map Constructs a list of a specific size or with elements of a specific value or with a specific allocator or as a copy of some other map.
max_size Returns the maximum length of the map.
rbegin Returns an iterator addressing the first element in a reversed map.
rend Returns an iterator that addresses the location succeeding the last element in a reversed map.
size Returns the number of elements in the map.
swap Exchanges the elements of two maps.
upper_bound Returns an iterator to the first element in a map that with a key value that is greater than that of a specified key.
value_comp Retrieves a copy of the comparison object used to order element values in a map.
Operators
operator[] Inserts an element into a map with a specified key value.
map Class | Thread Safety in the Standard C++ Library
Typedefs
allocator_type A type that represents the allocator class for the map object.
const_iterator A type that provides a bidirectional iterator that can read a const element in the map.
const_pointer A type that provides a pointer to a const element in a map.
const_reference A type that provides a reference to a const element stored in a map for reading and performing const operations.
const_reverse_iterator A type that provides a bidirectional iterator that can read any const element in the map.
difference_type A signed integer type that can be used to represent the number of elements of a map in a range between elements pointed to by iterators.
iterator A type that provides a bidirectional iterator that can read or modify any element in a map.
key_compare A type that provides a function object that can compare two sort keys to determine the relative order of two elements in the map.
key_type A type that describes the sort key object which constitutes each element of the map.
mapped_type A type that represents the data type stored in a map.
pointer A type that provides a pointer to a const element in a map.
reference A type that provides a reference to an element stored in a map.
reverse_iterator A type that provides a bidirectional iterator that can read or modify an element in a reversed map.
size_type An unsigned integer type that can represent the number of elements in a map
value_type A type that provides a function object that can compare two elements as sort keys to determine their relative order in the map.
Member Functions
begin Returns an iterator addressing the first element in the map.
clear Erases all the elements of a map.
count Returns the number of elements in a map whose key matches a parameter-specified key.
empty Tests if a map is empty.
end Returns an iterator that addresses the location succeeding the last element in a map.
equal_range Returns an iterator that addresses the location succeeding the last element in a map.
erase Removes an element or a range of elements in a map from specified positions
find Returns an iterator addressing the location of an element in a map that has a key equivalent to a specified key.
get_allocator Returns a copy of the allocator object used to construct the map.
insert Inserts an element or a range of elements into the map at a specified position.
key_comp Retrieves a copy of the comparison object used to order keys in a map.
lower_bound Returns an iterator to the first element in a map that with a key value that is equal to or greater than that of a specified key.
map Constructs a list of a specific size or with elements of a specific value or with a specific allocator or as a copy of some other map.
max_size Returns the maximum length of the map.
rbegin Returns an iterator addressing the first element in a reversed map.
rend Returns an iterator that addresses the location succeeding the last element in a reversed map.
size Returns the number of elements in the map.
swap Exchanges the elements of two maps.
upper_bound Returns an iterator to the first element in a map that with a key value that is greater than that of a specified key.
value_comp Retrieves a copy of the comparison object used to order element values in a map.
Operators
operator[] Inserts an element into a map with a specified key value.
#9
兄弟,找本C++的教科书看看,你的问题太基础了。推荐《C++程序设计语言(特别版)》,C++之父Bjarne Stroustrup博士写的,裘宗燕教授翻译。
#10
up
#11
回复:proton(落花有意,流水无情)
主要是insert时类型不匹配。可以这样:
.h文件中:typedef map<xxx, yyy>::value_type valType;
.cpp文件中:yourmap.insert(valType(xxx_实际值,yyy_实际值));
主要是insert时类型不匹配。可以这样:
.h文件中:typedef map<xxx, yyy>::value_type valType;
.cpp文件中:yourmap.insert(valType(xxx_实际值,yyy_实际值));