随笔分类 -  C++

摘要:1 #include 2 using namespace std; 3 4 template 5 class myclass 6 { 7 public: 8 T t; 9 void show(T tx) 10 { 11 cout t1; 29 30 //检测某个模板有没有根据某个类型实例化 31 __if_exis... 阅读全文
posted @ 2018-03-12 22:20 喵小喵~ 阅读(482) 评论(0) 推荐(0)
摘要:初始化单向链表 1 forward_list<int> list1{ 1,2,3,4,5 }; 链表排序 1 list1.sort();//排序 前插 1 list1.push_front(10); 链表反转 1 list1.reverse(); 链表头结点 1 auto ib = list1.be 阅读全文
posted @ 2018-03-12 21:13 喵小喵~ 阅读(122) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 //显示{}中的数据 6 void show(initializer_list list) 7 { 8 for (auto i : list) 9 { 10 cout list) 16 { 17 int length = list.s... 阅读全文
posted @ 2018-03-12 20:07 喵小喵~ 阅读(128) 评论(0) 推荐(0)
摘要:声明+delete:函数禁止使用.可以使一个类禁止释放 阅读全文
posted @ 2018-03-12 19:58 喵小喵~ 阅读(154) 评论(0) 推荐(0)
摘要:数据类型转换(static_cast) //数据类型转换 printf("%d\n", static_cast<int>(10.2)); 指针类型转换(reinterpret_cast) 1 指针类型转换 2 int *pint = new int(1); 3 char *pch = reinter 阅读全文
posted @ 2018-03-12 19:55 喵小喵~ 阅读(6878) 评论(0) 推荐(0)
摘要:要想解决死锁就需要lock与unlock成对使用,不允许连续使用两个lock 阅读全文
posted @ 2018-03-12 17:12 喵小喵~ 阅读(128) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 //通过mutex 等待事件响应 10 condition_variable isfull, isempty;//处理两种情况 11 mutex m; 12 bool flag =... 阅读全文
posted @ 2018-03-12 16:47 喵小喵~ 阅读(129) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 condition_variable cv; 11 mutex m; 12 bool done = false; 13 14 void run() 15... 阅读全文
posted @ 2018-03-12 16:08 喵小喵~ 阅读(313) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 #define N 100000 7 8 mutex g_mutex; 9 10 void add(int *p) 11 { 12 for (int i = 0; i lgd(g_mutex); 16 //unique也能... 阅读全文
posted @ 2018-03-12 15:56 喵小喵~ 阅读(199) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 //交换线程,线程移动 6 void main() 7 { 8 thread t1([]() {cout << "hello" << endl; }); 9 thread t2([]() {cout << "hello3" << endl; }); 10 ... 阅读全文
posted @ 2018-03-12 15:49 喵小喵~ 阅读(149) 评论(0) 推荐(0)
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 #define COUNT 1000000 10 11 //创建互斥量 12 mutex m; 13 14 //多... 阅读全文
posted @ 2018-03-12 15:23 喵小喵~ 阅读(153) 评论(0) 推荐(0)
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 int go(const char *fmt, ...) 9 { 10 va_list ap;//指针 11 va_start(ap, fmt)... 阅读全文
posted @ 2018-03-12 15:00 喵小喵~ 阅读(178) 评论(0) 推荐(0)
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include //线程将来的结果 5 #include 6 #include 7 using namespace std; 8 9 mutex g_m; 10 11 12 void main() 13 { 14 auto run = [... 阅读全文
posted @ 2018-03-12 14:44 喵小喵~ 阅读(174) 评论(0) 推荐(0)
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 //线程通信,结合mutex 9 //一个线程,多个线程处于等待,通知一个或者通知多个 10 11 mutex m;//线程相互排斥 12 conditio... 阅读全文
posted @ 2018-03-12 11:26 喵小喵~ 阅读(149) 评论(0) 推荐(0)
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 promise val;//全局通信变量 10 void main() 11 { 12 //字符串相加 13 /*st... 阅读全文
posted @ 2018-03-12 10:59 喵小喵~ 阅读(281) 评论(0) 推荐(0)
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 using namespace std; 6 7 class fun 8 { 9 public: 10 char str[100]; 11 public: 12 fun(char *str) 13 { 14 ... 阅读全文
posted @ 2018-03-12 10:47 喵小喵~ 阅读(165) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 //伪函数,可以将对象名当做函数来使用 6 struct func 7 { 8 func() 9 { 10 cout << "create "<< endl; 11 } 12 ~func() 13 { 14 ... 阅读全文
posted @ 2018-03-12 10:40 喵小喵~ 阅读(134) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 //声明类 7 class myclass; 8 9 struct info 10 { 11 myclass *p;//指针,内存首地址 12 int n;//代表有多少个对象 13 }; 14 15 ... 阅读全文
posted @ 2018-03-12 10:33 喵小喵~ 阅读(254) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 //全局内存管理,统计释放内存,分配内存 6 7 //重载全局的new 8 void *operator new(size_t size) 9 { 10 cout << "g_new call" << endl; 11 void *p = malloc(si... 阅读全文
posted @ 2018-03-11 23:01 喵小喵~ 阅读(240) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 8 void main() 9 { 10 //获取线程id 11 thread th1([]() { 12 //等待 13 this_thread::sleep_for(chro... 阅读全文
posted @ 2018-03-11 21:40 喵小喵~ 阅读(148) 评论(0) 推荐(0)