c++,my_map.find(a),如果找不到该字符串会返回什么?
3个回答
展开全部
std::map::find iterator find( const Key& key );
const_iterator find( const Key& key ) const;
Finds an element with key key.
Parameters
key - key value of the element to search for
Return value
Iterator to an element with key key. If no such element is found, past-the-end (see end()) iterator is returned.
找不到的话, 返回end迭代器
const_iterator find( const Key& key ) const;
Finds an element with key key.
Parameters
key - key value of the element to search for
Return value
Iterator to an element with key key. If no such element is found, past-the-end (see end()) iterator is returned.
找不到的话, 返回end迭代器
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <map>
using namespace std;
int main ()
{ typedef map<int,char> M;
char ch = 'A'; M m;
for ( int i=0; i<5; i++ )
m[i] = ch++; M::iterator It = m.begin();
cout << "map m:" << endl;
while ( It != m.end() )
{ cout << (*It).first << " - " << (*It).second << endl; It++; }
It = m.find(4);
if ( It != m.end() )
cout << "element key '4' has value " << (*It).second << endl;
else cout << "element key '4' not found" << endl; return 0; }
OUTPUT: // map m: // 0 - A // 1 - B // 2 - C // 3 - D // 4 - E // element key '4' has value E
#include <map>
using namespace std;
int main ()
{ typedef map<int,char> M;
char ch = 'A'; M m;
for ( int i=0; i<5; i++ )
m[i] = ch++; M::iterator It = m.begin();
cout << "map m:" << endl;
while ( It != m.end() )
{ cout << (*It).first << " - " << (*It).second << endl; It++; }
It = m.find(4);
if ( It != m.end() )
cout << "element key '4' has value " << (*It).second << endl;
else cout << "element key '4' not found" << endl; return 0; }
OUTPUT: // map m: // 0 - A // 1 - B // 2 - C // 3 - D // 4 - E // element key '4' has value E
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
my_map是什么东西 ?
追问
map my_Map;
追答
找到的话就是返回那个key所在的iterator,找不到就反回my_Map.end()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询