有关map的输入 c++
已经有
<br>typedef pair <int, int> Map_Int_Pair;
<br>
<br> m1.insert ( Map_Int_Pair ( 1, 10 ) );
<br> m1.insert ( Map_Int_Pair ( 2, 20 ) );
<br> m1.insert ( Map_Int_Pair ( 3, 30 ) );
<br>再加
<br>// Using pair as a return type for a function
<br> pair< map<int,int>::iterator, bool > pr1, pr2;
<br> pr1 = m1.insert ( Map_Int_Pair ( 4, 40 ) );
<br> pr2 = m1.insert ( Map_Int_Pair (1, 10 ) );
<br>运行
<br> if( pr1.second == true )
<br> {
<br> cout << "The element (4,40) was inserted successfully in m1."
<br> << endl;
<br> }
<br> else
<br> {
<br> cout << "The element with a key value ofn"
<br> << " ( (pr1.first) -> first ) = " << ( pr1.first ) -> first
<br> << " is already in m1,n so the insertion failed." << endl;
<br> }
<br>
<br> if( pr2.second == true )
<br> {
<br> cout << "The element (1,10) was inserted successfully in m1."
<br> << endl;
<br> }
<br> else
<br> {
<br> cout << "The element with a key value ofn"
<br> << " ( (pr2.first) -> first ) = " << ( pr2.first ) -> first
<br> << " is already in m1,n so the insertion failed." << endl;
<br> }
<br>}
<br>
<br>结果:
<br>The element (4,40) was inserted successfully in m1.
<br>The element with a key value of
<br> ( (pr2.first) -> first ) = 1 is already in m1,
<br> so the insertion failed.
<br>
<br>我想问的是已经有的就不能再重复往里输了吗?

- 这是一篇来自百度知道的问题
|