随笔 - 480  文章 - 0 评论 - 45 阅读 - 73万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

07 2021 档案
C++基础-正则实战(日期拆分regex_match ,符号拆分sregex_token_iterator, 邮箱的查找 regex_search)
摘要:1.日期拆分 由于日期是固定格式的,如1994/01/08 因此使用regex_match 可以进行结果的匹配 int main3() { //1999 12 25 regex reg("^(\\d{4})/(0?[1-9]|1[0-2]])/(0?[1-9]|[1-2][0-9]|3[0-1])$ 阅读全文
posted @ 2021-07-27 01:01 python我的最爱 阅读(1043) 评论(0) 推荐(0) 编辑
C++基础-正则表达式 regex_match(匹配) regex_search(查找) regex_replace(替换)
摘要:正则匹配中的基础符号 ^开头()组[]或,{}几次$结尾 1.regex_match(匹配) 判断当前的结构体是否符合正则匹配规则 #include<iostream> #include<regex> using namespace std; //regex_match 匹配 //regex_sea 阅读全文
posted @ 2021-07-26 01:23 python我的最爱 阅读(4095) 评论(0) 推荐(0) 编辑
C++基础-inline(内联函数)
摘要:使用内联函数就相当于是使用lamdba函数,对于函数的命令指令直接进行替换 #include<iostream> #include<cstdlib> using namespace std; #define f(x) x*x*x; //C语言内联, c++严格要求类型 inline int get( 阅读全文
posted @ 2021-07-21 00:55 python我的最爱 阅读(139) 评论(0) 推荐(0) 编辑
C++基础-assert(断言),static_assert(静态断言)
摘要:1.断言(assert) #include<iostream> #include<cassert> using namespace std; //区别用指针的大小 int divv(int a, int b) { assert(b != 0); //断言 return a / b; } int ma 阅读全文
posted @ 2021-07-21 00:01 python我的最爱 阅读(305) 评论(0) 推荐(0) 编辑
C++基础-绑定lamda和operator函数
摘要:1.使用bind构造适配器操作,这里可以使用默认的参数 #include<iostream> #include<functional> using namespace std; using namespace std::placeholders; int add(int a, int b, int 阅读全文
posted @ 2021-07-20 23:38 python我的最爱 阅读(70) 评论(0) 推荐(0) 编辑
C++基础-绑定类成员函数 bind(&MyStruct::add1, &my1, _1)
摘要:使用bind可以将函数从类成员变量中提取出来 这里以结构体的类成员函数作为说明 #include<iostream> #include<functional> using namespace std; using namespace std::placeholders; struct MyStruc 阅读全文
posted @ 2021-07-18 13:44 python我的最爱 阅读(400) 评论(0) 推荐(0) 编辑
C++基础-模板嵌套(void showwall(vector<T1>(v), list<T2>l))
摘要:模板的嵌套指的是模板里面嵌套数据类型如vector和list等 // // Created by Administrator on 2021/7/17. // #include<iostream> #include<vector> #include<list> using namespace std 阅读全文
posted @ 2021-07-17 22:35 python我的最爱 阅读(181) 评论(0) 推荐(0) 编辑
C++基础-函数包装器(function)
摘要:1.使用function定义一个函数模板,然后将函数模板进行赋值 function<int(int, int)> fun1 = add; //包装函数 2.构造函数模板, 将函数进行做输入进行传递 template<class T, class F> T run(T t1, T t2, F f) { 阅读全文
posted @ 2021-07-17 20:14 python我的最爱 阅读(246) 评论(0) 推荐(0) 编辑
C++基础-单链表(ForwardList)
摘要:单链表是一种向前操作的数据结构 1.初始化 forward_list<int> list1{11, 2, 13, 4, 15} 2.排序 list1.sort() 3.翻转 list1.reverse(); 4.合并 list1.merge(list2) 5.初始化 list1.assign(10, 阅读全文
posted @ 2021-07-14 01:22 python我的最爱 阅读(160) 评论(0) 推荐(0) 编辑
C++基础-大括号匹配initializer_list<int> list(直接传入{]数据)
摘要:使用initializer_list<int> 可以使用{}作为参数传入到函数中 #include<iostream> #include<initializer_list> using namespace std; void show(initializer_list<int> list) { fo 阅读全文
posted @ 2021-07-14 00:12 python我的最爱 阅读(166) 评论(0) 推荐(0) 编辑
C++基础-delete使用1.(精准匹配)2.(删除构造和析构)
摘要:1. 删除其他类型的输入函数,可以保证精准匹配输入 #include<iostream> using namespace std; //函数声明 = delete; void show(char num) = delete; //精确匹配, 删除额外的情况 void show(int num) = 阅读全文
posted @ 2021-07-13 23:37 python我的最爱 阅读(285) 评论(0) 推荐(0) 编辑
C++基础-类型转换-static_cast(基本类型转换) reinterpret_cast(指针类型转换) const_cast(const数据转换) dynamic_cast(父类子类转换)
摘要:1.static_cast基本类型转换 int main1() { //printf("%d", 10.2); //printf("%f", (float)1); //printf不会完成数据类型转换 //printf("%d", static_cast<int>(10.2)); //默认转换 pr 阅读全文
posted @ 2021-07-13 23:13 python我的最爱 阅读(215) 评论(0) 推荐(0) 编辑
Leetcode 1838. 最高频元素的频数-C++
摘要:题目描述: 元素的 频数 是该元素在一个数组中出现的次数。 给你一个整数数组 nums 和一个整数 k 。在一步操作中,你可以选择 nums 的一个下标,并将该下标对应元素的值增加 1 。 执行最多 k 次操作后,返回数组中最高频元素的 最大可能频数 。 示例 1: 输入:nums = [1,2,4 阅读全文
posted @ 2021-07-12 23:29 python我的最爱 阅读(141) 评论(0) 推荐(0) 编辑
C++基础-消费者和生产者模式
摘要:消费者和生产者模式 1.生产者,在数量少于10的时候,不断生产,并且通知消费者,开始消费, 等于10的时候,加锁进行等待 2.消费者, 在数量大于0的时候,不断消费,并且通知生产者,开始生产,等于0的时候,加锁进行等待 // // Created by Administrator on 2021/7 阅读全文
posted @ 2021-07-07 23:56 python我的最爱 阅读(560) 评论(0) 推荐(0) 编辑
C++基础-等待固定时间cv.wait_until(lk, end)(等待固定时间) chrono::high_resolution_clock::now()(获得当前时间)
摘要:使用cv.wait_unitil(lk, end)等待固定的时间 int run() { auto start = chrono::high_resolution_clock::now(); //当前时间 auto end = start + chrono::milliseconds(5000); 阅读全文
posted @ 2021-07-07 23:14 python我的最爱 阅读(1716) 评论(0) 推荐(0) 编辑
C++基础-lock_guard和unique_lock
摘要:lock_guard(自动加锁, 自动解锁, 读取失败就一直等待) lock_guard<mutex> lgd(g_mutex); unique_lock(自动加锁, 自动解锁, 根据块语句锁定) unique_lock<mutex> ulk(g_mutex); 完整代码 #include<thre 阅读全文
posted @ 2021-07-03 14:25 python我的最爱 阅读(212) 评论(0) 推荐(0) 编辑
C++基础-move进行线程的赋值
摘要:将一个线程移动到另外一个线程,其中的一个线程被销毁 // // Created by Administrator on 2021/7/3. // #include<thread> #include<iostream> #include<cstdlib> using namespace std; // 阅读全文
posted @ 2021-07-03 14:20 python我的最爱 阅读(224) 评论(0) 推荐(0) 编辑
C++基础-swap交换线程
摘要:使用swap进行两个线程的交换 #include<thread> #include<iostream> using namespace std; //交换线程 int main1() { thread t1([](){cout << "fangfang"<<endl;}); thread t2([] 阅读全文
posted @ 2021-07-03 14:03 python我的最爱 阅读(199) 评论(0) 推荐(0) 编辑
C++基础-多线程循环打印结果unique_lock<mutex>ulk(m)(设定锁定) cv.wait(ulk)(设置等待) cv.notify_all(通知全部)
摘要:第一步: 设置unique_lock<mutex> ulk(m) //设定锁定 第二步: 每一个线程在循环中等待, cv.wait(ulk) //不是该出现的场合等着 第三步: cv.notify_all() //通知其他的线程,进行执行 // // Created by Administrator 阅读全文
posted @ 2021-07-03 13:47 python我的最爱 阅读(436) 评论(0) 推荐(0) 编辑
C++基础-死锁和解锁(g_mutex.lock(), g_mutex.unlock())
摘要:当多个函数操作同一个锁时,锁住一个变量时要尽快解锁,不要同时锁住一个相同的变量,这时就容易发生死锁的情况 // // Created by Administrator on 2021/7/2. // #include<iostream> #include<mutex> #include<thread 阅读全文
posted @ 2021-07-02 23:59 python我的最爱 阅读(850) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示