我正在尝试检查给定的密钥是否在地图中,有些不能这样做:
typedef map<string,string>::iterator mi;
map<string, string> m;
m.insert(make_pair("f","++--"));
pair<mi,mi> p = m.equal_range("f");//I'm not sure if equal_range does what I want
cout << p.first;//I'm getting error here
Run Code Online (Sandbox Code Playgroud)
那么如何打印p中的内容呢?
检查元素是否包含在数组/列表中的C++方法是什么,类似于inPython中的运算符?
if x in arr:
print "found"
else
print "not found"
Run Code Online (Sandbox Code Playgroud)
与Python的in运算符相比,C++等价物的时间复杂度如何?
我有两个stl地图map<int,int> ,我想比较它们..所以这里是代码..
map <int, int> a,b;
insert into a and b;
map<int,int>::iterator i;
for(i=a.begin();i!=a.end();i++){
if(what should be here?)
then cout << (*i).first << " also present in b" << endl;
}
Run Code Online (Sandbox Code Playgroud)
我希望像(b [(*i).first])之类的东西存在?
我想使用find()方法来捕获我的std :: map()的特定元素
现在返回值是我正在寻找的元素,或者它指向地图的末尾(如果找不到元素)(Cf:http://www.cplusplus.com/reference/map/map/找/).
所以我正在使用这两个信息来决定元素是否在地图中.但是如果元素已经在内部但在最后呢?会发生什么?然后,我的if-query将决定它不存在,因此我的程序将被编制.
我是否正确使用这个例程,如果,如何预防呢?
感谢您的支持