随笔分类 - C++
摘要:TextQuery类用来读取文本并提取每个单词出现的行并保存该行至容器map中 QueryResult类用来查询单词是否出现并打印结果。 使用shared_ptr来避免TextQuery对象先于QueryResult销毁,导致程序无法正常执行。
阅读全文
摘要:智能指针有一个计数器,每次拷贝,传递等操作都会增加其计数器的值,当其计数器归0时会释放内存,因此不能混合使用常规指针与智能指针,当常规指针new得一块内存后,此时将其指向的内存传递给智能指针使用将会引起智能指针提前释放申请的内存,后面常规指针将无法正常使用,变为一个空悬指针(指向已经销毁的对象或已经
阅读全文
摘要:using namespace std; using namespace std::placeholders; bool comP(string &a, string& b) { return a head; string v; while (getline(ifile, v)) { head.push_back(v); } so...
阅读全文
摘要:#pragma once #define _CRT_SECURE_NO_DEPRECATE #include <stdio.h> #include <iostream> #include <string> #include <cstring> #include <vector> #include <queue> #include <initializer_list> #include <algor
阅读全文
摘要:#include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; void ChangeImgBG(); Mat HandleImgData(Mat &img); /* 图片背景替换 知识点:分水岭分割、高斯模糊 处理步骤:数据组装-KMeans分割-背景消除-生成遮罩-模糊-输出
阅读全文
摘要:class YMD { private: unsigned int year; unsigned int month; unsigned int day; public: YMD(string date); void show() { cout << "today is " << year << "-" << month << "-" <<...
阅读全文
摘要:endl,ends,flush都可以刷新缓冲区。如果程序异常终止,输出缓冲区是不会被刷新的。当一个程序崩溃后,它所输出的数据很可能停留在输出缓冲区中等待打印。 当调试一个已经崩溃的程序时,需要确认那些你认为已经输出的数据确实已经刷新了。否则,可能将大量时间浪费在追踪代码为什么没有执行中,而实际上代码
阅读全文
摘要:排序算法的动图演示 冒泡排序 选择排序 插入排序 希尔排序 基数排序 归并排序 图片转自--https://www.runoob.com/w3cnote_genre/algorithm
阅读全文
摘要:int v = 0x0D0C0B0A; char* c = (char*)&v; if (*c == 0x0A) cout << "little endian"; else cout << "big endian";
阅读全文
摘要:括号匹配 //裁剪字符串,掐头去尾只保留被括号包围的部分 void trim(const char exp[], int& lo, int& hi) { while ((lo <= hi) && (exp[lo] != '(') && (exp[lo] != ')')) lo++; while ((
阅读全文
摘要:一个类,在未定义任何构造函数的情况下,创建该类对应的对象实体时,编译器会隐式的定义一个默认的构造函数--合成的默认构造函数,其按照如下规则初始化类的数据成员: 如果存在类内的初始化值,用它来初始化成员。 否则,默认初始化该成员。 然而,合成的默认构造函数只适合简单的类。对于一个普通的类来说,必须定义
阅读全文
摘要:constexpr函数(constexpr function)是指能用于常量表达式的函数。定义constexpr函数的方法与其他函数类似,不过要遵循几项约定:函数的返回类型及所有形参的类型都得是字面值类型,而且函数体中必须有且只有一条return语句: 我们把new_sz定义成无参数的constex
阅读全文
摘要:数组无法被拷贝,所以函数无法返回一个数组。但是,函数可以返回数组的指针或引用。下面是返回数组的指针或引用的方式: 其中arrT是含有10个整数的数组的别名、因为我们无法返回数组,所以将返回类型定义成数组的指针。因此,func函数接受一个int实参,返回一个指向包含10个整数的数组的指针。 声明一个返
阅读全文
摘要:As we’ve seen, a pointer is an object that can point to a different object. As a result,we can talk independently about whether a pointer is const and
阅读全文
摘要:using namespace std; string decodeString(const string& s, int& i); int main(void) { //3[z]2[2[y]pq4[2[jk]e1[f]]]ef string s = "3[z]2[2[y]pq4[2[jk]e1[f]]]ef"; int i = 0; string out = d...
阅读全文
摘要:Q1:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. Q2:A numeric sequence o
阅读全文
摘要:LeetCode中的一题,虽然结果没问题,但是超时了,下面的操作真的辣眼睛,记录一下犯蠢。
阅读全文
摘要:13-1 13-2 13-3 13-4
阅读全文
摘要:冒泡排序的数组和向量实现 向量唯一化实现 向量-归并排序
阅读全文
摘要:#include "pch.h" #include #include #include #include #include #include #include using namespace std; inline void eatline() { while (cin.get() != '\n') continue; } struct planet { char name...
阅读全文

浙公网安备 33010602011771号