随笔分类 - 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...
阅读全文
摘要:初始化单向链表 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
阅读全文
摘要: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...
阅读全文
摘要:数据类型转换(static_cast) //数据类型转换 printf("%d\n", static_cast<int>(10.2)); 指针类型转换(reinterpret_cast) 1 指针类型转换 2 int *pint = new int(1); 3 char *pch = reinter
阅读全文
摘要:要想解决死锁就需要lock与unlock成对使用,不允许连续使用两个lock
阅读全文
摘要: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 =...
阅读全文
摘要: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...
阅读全文
摘要: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也能...
阅读全文
摘要: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 ...
阅读全文
摘要: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 //多...
阅读全文
摘要: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)...
阅读全文
摘要: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 = [...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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 ...
阅读全文
摘要: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 ...
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文

浙公网安备 33010602011771号