标签:.com sdn clu ++ std 一个 second 为什么 net
bool operator 运算符 (const 结构体名称 b) const { return(什么时候这个运算符对结构体成立);//注意对此运算符使用this->元素名; }
首先为什么要用 char*作为std::map中的key
#include <cstring> struct cmp_str { bool operator()(char const *a, char const *b) { return std::strcmp(a, b) < 0; } }; int main ( int argc, char ** argv ) { std::map<const char*, int, cmp_str> map; map["aa"] = 1; map["ca"] = 2; map["ea"] = 3; map["ba"] = 4; map["ba"] = 5; map["bb"] = 6; map["ba"] = 7; std::map<const char*, int, cmp_str>::iterator it = map.begin(); for (; it != map.end(); it++ ) { std::cout << (*it).first << ": " << (*it).second << std::endl; } return 0; }
【基础】结构体重载,用 char*作为std::map中的key
标签:.com sdn clu ++ std 一个 second 为什么 net
原文地址:https://www.cnblogs.com/Kohinur/p/8977263.html