
c++
黄縢酒
这个作者很懒,什么都没留下…
展开
-
c++ 二进制、八进制、十六进制
进制表示输出十进制正常表示dec二进制0bbitset八进制0oct十六进制0xhex#include <iostream>#include <bitset>using namespace std;void test_radix(){ cout << "0b110: " << ...原创 2020-04-17 19:56:38 · 386 阅读 · 0 评论 -
shared_ptr的简单实现
shared_ptr:使用引用计数传入指针的构造函数拷贝构造函数赋值函数析构函数返回引用计数->和*的重载注意事项构造函数是explicit的,防止smart_ptr< int > sp = p 的使用计数需要用int**ptr++是先++的,所以需要括号或者++*ptrsmart_ptr.htemplate<typename T>c...原创 2020-04-14 17:45:52 · 177 阅读 · 0 评论 -
一行代码可以完成的事
一行代码可以完成的事最大公因数最小公倍数交换最大公因数int gcd(int a, int b) {return b? gcd(b, a%b) : a;}最小公倍数int lcm(int a, int b) {return a*b/gcd(a, b); }交换void swap(int& a, int& b) { a^=b^=a^=b; }// a^=b; b^=...原创 2020-03-12 16:12:32 · 103 阅读 · 0 评论 -
C++ 强制类型转换
强制类型转换const_castreinterpret_caststatic_cast & dynamic_castconst_castconst_cast用于修改类型的const、volatile属性。const_cast<?>(?), <>中必须是指针、引用或者右值 - (the type in a const_cast must be a pointer...原创 2020-02-03 13:51:42 · 1087 阅读 · 0 评论 -
c++ list删除
c++ std::list 是一个双向链表,使用list::iterator it遍历,当然auto写起来更简单;list<int> example_list;for (list<int>::iterator it = example_list->begin(); it != example_list->end(); ){ if ((*it)< ...原创 2019-04-15 22:45:29 · 938 阅读 · 0 评论