C++
文章平均质量分 60
雨过河源忆江南
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++ extern 在命名空间中的使用
在C++中使用命名空间中的全局变量,如何声明,才不会重复定义呢?(1)在test.h 中声明namespace try{ extern double gCameraMatrix[9]; extern double gDistCoeffs[4];}在test.cpp中定义namespace try{ double gCameraMatrix[9]; double gDi原创 2018-01-11 10:29:49 · 5003 阅读 · 0 评论 -
C++ 模板函数和模板类的实现
学习C++模板时练习的代码。模板函数:templatevoid swapNum(T &a, T &b){ T temp; temp = b; b = a; a = temp;}调用的时候: int aa = 5, bb = 6; swapNum(aa, bb); cout 模板类相对复杂,注意3点:(1)必须将类中方法的声明和定义都写在头文原创 2018-01-28 19:42:03 · 3061 阅读 · 0 评论 -
指针的按值传递,按址传递以及指针的引用
指针作为形参,最常用的是按址传递,如下:swap(int a, int b){ int t = a; a = b; b = t;} swap1(int *a, int *b){ int t = *a; *a = *b; *b = t; }int main(){ int a=2, b =3; swap(a,b...原创 2018-02-15 00:09:05 · 494 阅读 · 0 评论 -
C++读写文件,vector排序等
C++文件读写时,遇到的问题如下:// ConsoleApplication1.cpp: 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>#include<sstream>#include<fstream>#include<string>#include<vector&g...原创 2018-03-02 16:59:31 · 497 阅读 · 0 评论 -
char *输出的问题,以及指针的问题
char *word="again";cout<<word<<endl;cout<<(*word)<<endl;输出结果为:againachar *word="again";表示在静态存储区分配空间,并把“again”放在内存区域,因为静态存储区里的数据是不能改变!!!而在栈了也分配空间,并把"again”在静态存储区的首地址放在栈里的内存中原创 2018-03-11 20:36:08 · 5128 阅读 · 0 评论 -
vector对结构体排序的sort算法
转载自从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级。本文就sort函数在vector中的用法分为sort函数入门用法与自定义comp比较函数比较结构体这两个最基本的功能讲讲其用法:1、sort入门:使用sort需要包含algorithm头文件,完整代码如下#include&...转载 2018-03-20 20:37:02 · 1054 阅读 · 0 评论 -
python 正则表达式检验匹配数字和email
import redef match_signal(src,dst): m=re.match(src,dst) if m!=None: print('match ok') # print(m.group(0)) # print(m.group(1)) # print(m.group(2)) print(m.group()) else: print('fail') ...原创 2018-05-12 15:07:13 · 2682 阅读 · 0 评论 -
关于C++ vector等容器排序问题
C++ vector排序参考 https://blog.youkuaiyun.com/upc_xbt/article/details/53305962注意:#include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){ int num=0; c...原创 2018-05-26 21:29:18 · 2230 阅读 · 0 评论 -
排序算法性质总结
(1)稳定性:在排序之前,如果关键字Ki==Kj,并且i<j,称关键字Ki在Kj之前;如果在排序之后,Ki依然在Kj之前,则为稳定排序,反之为不稳定排序稳定排序有:冒泡排序,插入排序,归并排序,基数排序。 不稳定排序有:快速排序,希尔排序,简单选择排序,堆排序。 (2)算法的时间复杂度与初始排序无关:选择排序,堆排序,归并排序,基数排序在平均情况,最坏情况,最好情况下的时间复杂度均一致...原创 2018-05-27 11:05:29 · 1218 阅读 · 0 评论 -
c++实现在实例化时为每个对象添加唯一ID
用类的静态成员变量实现,在构造函数中增加ID的值,然后析构函数中减小ID的值。这样就保证了每次实例化时的ID唯一。然后将该静态成员变量赋值给私有变量即可。具体代码如下:类的声明:#pragma once#includeclass tank{public: tank(); ~tank(); void fire(); static int getCount(); int ge原创 2018-01-28 16:01:40 · 4460 阅读 · 0 评论 -
vector和list等容器之间的相互赋值
使用assign成员函数: list authors = { "jie","rice","pig" }; vectorarticles = { "a","an","the" }; articles.assign(authors.begin(), authors.end()); for (auto c : articles) { cout << c << endl; }原创 2018-01-18 10:32:33 · 6176 阅读 · 0 评论 -
类中定义数组提示:静态成员引用必须与特定对象相对
class A {private:int outHeight = 24;int outWidth = 660;unsigned short distData[outHeight * outWidth];}想定义类中数组,但是,会提示:静态成员引用必须与特定对象相对。当改为静态成员变量:static int outHeight = 24;提示:带有类内初始值设定项原创 2018-01-11 18:24:34 · 1007 阅读 · 0 评论 -
在VS2013 使用C语言库函数,出现出现错误,提示使用不安全函数use _CRT_SECURE_NO_WARNINGS
在VS2013 使用C语言库函数,出现出现错误,提示使用不安全函数use _CRT_SECURE_NO_WARNINGS转载 2018-01-12 15:33:40 · 462 阅读 · 0 评论 -
vs读取txt文件一直失败
在工程目录下用记事本新建了一个txt文件,try.txt,然后用vs读取该txt文件 string file = "try.txt"; ifstream in; in.open(file.data()); if (!in.is_open()) { cout << "can't open the txt"<<endl; } string line; cou原创 2018-01-21 20:15:21 · 9145 阅读 · 3 评论 -
c++读写文件
c++读写文件与容器等结合:// try_code.cpp: 定义控制台应用程序的入口点。//#include "stdafx.h"#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;struct原创 2018-01-21 22:06:45 · 342 阅读 · 0 评论 -
c++不错学习教程
C++小白教程转载 2018-01-07 16:51:11 · 355 阅读 · 0 评论 -
C++ 模板,二分法寻找vector中指定元素位置
练习模板,vector的时候,尝试写二分法。代码记录如下:#include "stdafx.h"#include #include#includeusing namespace std;//二分法寻找指定元素在vector的位置//注意二分法中的元素要事先排序templateint find_element(vector&ver, T num){ auto beg=原创 2018-01-17 17:58:46 · 2560 阅读 · 0 评论 -
C/C++ 获取数组的有效长度
(1)字符数组。采用如下strlen()最简单。char b[] = "abc";cout 输出3注意:存储字符串的字符数组末尾有一个'/0'字符,因此cout << sizeof(b) / sizeof(b[0]) << endl;cout 得到的结果都为4,应该修改。(2)其他情况,则如下都行:int a[] = { 1,2,3 };cout << sizeof(a)/sizeof(a[原创 2018-01-17 19:10:04 · 15478 阅读 · 0 评论
分享