|
//
防止VC6长文件名警告
#pragma warning(disable:
4786
)
#include
<
map
>
#include
<
string
>
using
namespace
std;
int
main(
int
argc,
char
*
argv[])
{ typedef map
<
string
,
string
>
MapParam; typedef pair
<
string
,
string
>
Param; map
<
string
,
string
>
::iterator pIter;
MapParam
params
;
params
.insert(Param(
"
key1
"
,
"
value1
"
));
params
.insert(Param(
"
key2
"
,
"
value2
"
));
params
[
"
key1
"
]
=
"
v1
"
;
params
[
"
key2
"
]
=
"
v2
"
;
//
如果有key存在则覆盖
params
.insert(Param(
"
key1
"
,
"
value1
"
));
//
注意如果key存在,不会覆盖
for
(pIter
=
params
.begin(); pIter
!=
params
.end(); pIter
++
)
//
遍历
{ printf(
"
%s,%s\n
"
, pIter
->
first.c_str(), pIter
->
second.c_str()); }
if
(
params
.find(
"
key2
"
)
!=
params
.end())
//
查询
{ printf(
"
find=%s\n
"
,
params
[
"
key2
"
].c_str()); }
return
0
; }
|