C++复习之STL(二)——谈一谈关联式容器set和有序vector的使用选择问题
摘要:1.set的宣言 先看看C++标准中对set的介绍: A set is a kind of associative container that supports unique keys (contains at most oneof each key value) and provides for fast retrieval of the keys themselves. Set suppor...
阅读全文
阅读源码(0)——VC中的assert.h,10多行代码两个宏,值得推敲推敲
摘要:/****assert.h - define the assert macro****/#include <crtdefs.h>//移除可能的assert定义,确保assert未定义//但据测试,“后面”的#defines会覆盖之前的#defines//这里考虑周全,值得学习!#undef assert//如果定义了NDEBUG,那么关闭assert宏//在Release模式下,会自动定义NDEB...
阅读全文
输入1则输出0,输入0则输出1
摘要:那天小面试了吧,遇到这么个问题:输入0则输出1,输入1则输出0,当时想出前三种,最近在思考到底有没有其他方法来解答。 1.最常见的IF-ELSE解法,最先进入脑海,当然,还有点傻傻的问HR,if-else判断算一种么? 1: #include <iostream> 2: 3: using namespace std; 4: int main() 5: { 6: int input; 7: cin ...
阅读全文
C++复习之STL(一)—— erase和remove特异行为
摘要:C++的STL通过iterator将container和algorithm分离,并通过functor提供高可定制性。iterator可以看作是一种契约,algorithm对iterator进行操作,algorithm很难对container进行直接操作,这是因为algorithm对container所知甚少,一段代码,若未利用操作对象所知全部信息,将难以达到性能之极,并伴随其它种种折中现象。当然,...
阅读全文