Android Ndk 学习笔记(目录)
void useMap(){
map<int ,string> mapVar ;
mapVar.insert(pair<int,string>(1,"一"));
mapVar.insert(make_pair(2,"er"));
mapVar.insert(map<int,string>::value_type(3,"san"));
mapVar[4] = "si";
mapVar[4] = "asd";
for (map<int,string>::iterator it = mapVar.begin(); it!=mapVar.end() ; it++) {
cout << it->first << "," << it->second.c_str() <<endl ;
}
std::pair<map<int,string>::iterator , bool> result = mapVar.insert(make_pair(5,"5"));
if (result.second){
cout << "success" << endl;
}else{
cout << "faile" << endl;
}
map<int, string> ::iterator findResult = mapVar.find(3);
if (findResult != mapVar.end()) {
cout << "找到了" << findResult->first << "," << findResult->second.c_str() << endl;
} else {
cout << "没找到" << endl;
}
}
void useMultimap(){
multimap<int, string> multimapVar;
multimapVar.insert(make_pair(10, "十个1"));
multimapVar.insert(make_pair(10, "十个2"));
multimapVar.insert(make_pair(10, "十个3"));
multimapVar.insert(make_pair(30, "三十1"));
multimapVar.insert(make_pair(30, "三十3"));
multimapVar.insert(make_pair(30, "三十2"));
multimapVar.insert(make_pair(20, "二十1"));
multimapVar.insert(make_pair(20, "二十2"));
multimapVar.insert(make_pair(20, "二十3"));
for (auto iteratorVar = multimapVar.begin(); iteratorVar != multimapVar.end() ; iteratorVar ++) {
cout << iteratorVar->first << "," << iteratorVar->second << endl;
}
cout << endl;
int result;
cout << "请输入你要查询的key,为int类型:" << endl;
cin >> result;
multimap<int, string>::iterator iteratorVar = multimapVar.find(result);
while (iteratorVar != multimapVar.end()) {
cout << iteratorVar->first << "," << iteratorVar->second << endl;
iteratorVar++;
if (iteratorVar->first != result) {
break;;
}
if (iteratorVar == multimapVar.end()) {
break;;
}
}
}
class ComPareObject{
public:
void operator()(){
cout << "仿函数" << endl;
}
};
void fun2() {
cout << "普通函数" << endl;
}
void showAction(int content) {
cout << "自定义 一元谓词" << content << endl;
}
class showActionObj {
public:
void operator()(int content) {
cout << "自定义仿函数" << content << endl;
}
};
class showActionObj2 {
public:
int count = 0;
void _count() { cout << "本次输出次数是:" << this->count << endl; }
void operator() (int __first) {
cout << "仿函数" << __first << endl;
count++;
}
};
void useForeach(){
set<int> setVar ;
setVar.insert(10);
setVar.insert(10);
setVar.insert(10);
setVar.insert(10);
setVar.insert(10);
for_each(setVar.begin(),setVar.end(),showAction);
for_each(setVar.begin(),setVar.end(),showActionObj());
showActionObj2 s2 ;
s2 = for_each(setVar.begin(),setVar.end(),s2);
s2._count();
}
void usePlus(){
plus<int> add_func;
int r = add_func(1, 1);
cout << r << endl;
plus<string> add_func2;
string r2 = add_func2("AAAA", "BBB");
cout << r2 << endl;
plus<float> add_func3;
float r3 = add_func3(4354.45f, 34.3f);
cout << r3 << endl;
}
template<typename T>
struct plus_d{
T operator()(const T & t1 ,const T & t2){
return t1+t2;
}
};
void usePlusd(){
plus_d<int> add_func;
int r = add_func(1, 1);
cout << r << endl;
plus_d<string> add_func2;
string r2 = add_func2("AAAA", "BBB");
cout << r2 << endl;
plus_d<float> add_func3;
float r3 = add_func3(4354.45f, 34.3f);
cout << r3 << endl;
}