STL和基本编程
1.map
在map中,由key查找value时,首先要判断map中是否包含key
if(m.count(key)>0) { return m[key]; } return null;
或者
iter = m.find(key); if(iter!=m.end()) { return iter->second; } return null;
前一种方法很直观,但是效率差很多。因为前面的方法,需要执行两次查找。因此,推荐使用后一种方法。
map<string, string> m;
m.insert(std::make_pair(doc["exec_unit"][i]["id"].GetString(), euiptr.get()));
2. string
push_back() 用于在字符串后面追加一个字符
string s="hello"; s.push_back('c'); //输出helloc
str.append("hello"); //append追加字符串
str.assign("hello"); //assign 方法可以理解为先将原字符串清空,然后赋予新的值作替换
3.vector
EUIPtr euiptr(new ExecUnitInfo)
vec.push_back(std::move(euiptr));