![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
yinhe888675
这个作者很懒,什么都没留下…
展开
-
C++实现链表
#pragma once#ifndef MY_LIST#define MY_LIST#include <iostream>#include <stdlib.h> #include <time.h>#include <string.h>using namespace std;struct ListNode{ int data; ListNode * next;};class MyList{public: MyList(); ~原创 2021-03-08 09:06:27 · 263 阅读 · 0 评论 -
c++单例模式
c++单例模式#include "stdafx.h"#include <iostream>#include<vector>#include<string>#include <mutex>using namespace std;class Singleton{public: static Singleton * getInstance() { if (m_pInstance == nullptr) { m_oLock.loc原创 2021-02-22 11:25:25 · 87 阅读 · 0 评论 -
c++随机数
srand((unsigned)time(null));(a,b) (rand()%(b-a+1))+a-1[a,b) (rand()%(b-a))+a(a,b] (rand()%(b-a))+a+1[a,b] (rand()%(b-a+1))+ac++11: std::default_random_engine _random(time(0)); std::unif原创 2016-01-29 10:17:45 · 322 阅读 · 0 评论 -
c++中string 的replace用法
/*用法一: *用str替换指定字符串从起始位置pos开始长度为len的字符 *string& replace (size_t pos, size_t len, const string& str); */ int main() { string line = "this@ is@ a test string!";转载 2016-03-18 10:07:06 · 101250 阅读 · 3 评论 -
C++ STL中vector、list、deque和map的区别
1 vector 向量 相当于一个数组 在内存中分配一块连续的内存空间进行存储。支持不指定vector大小的存储。STL内部实现时,首先分配一个非常大的内存空间预备进行存储,即capacituy()函 数返回的大小,当超过此分配的空间时再整体重新放分配一块内存存储,这给人以vector可以不指定vector即一个连续内存的大小的感觉。通常此默认的内存分配 能完成转载 2016-04-01 10:24:07 · 806 阅读 · 0 评论 -
C++字符串分割
char str2[] = "a,b,c,d*e"; const char * split = ","; char * p; char *next_token = nullptr; p = strtok_s(str2, split, &next_token); while (p != nullptr) { printf("%s\n", p); p = str原创 2016-03-15 17:28:30 · 391 阅读 · 0 评论 -
C++位操作符
1、与运算(&) 双目运算。二个位都置位(等于1)时,结果等于1,其它的结果都等于0。2、 或运算(|)双目运算。二个位只要有一个位置位(等于1),结果就等于1。二个位都为0时,结果为0。3、异或运算(^) 双目运算。二个位不相等时,结果为1,否则为0。4、非运算(~) 单目运算。位值取反,置0为1,或置1为0。5、移位运算(>>原创 2016-03-29 10:27:11 · 343 阅读 · 0 评论 -
C++,为什么str=new char[strlen(s)+1];中要加1
因为strlen是计算字符串有多少字符的,不包括结束符,所以加一。如"abc",占四个字节,strlen的值是3//释放实例自身已有内存 delete[] m_pData; m_pData=NULL;//在删除自身内存以后在重新new一个长度为len+1的字符数组,类似拷贝构造函数 int len=strlen(str.m_pData); m_pDat...转载 2019-05-08 13:46:58 · 1609 阅读 · 0 评论 -
打印回型数组-回型矩阵-环形数组
刚才看到打印回形矩阵(或者回型数组、环形数组),网上一些方法感觉写的挺麻烦,还是自己写一遍吧,不妥之处还请各位看官不吝赐教。题目:输入一个整数N,打印出从1~N*N的N*N矩阵。比如N = 3,构成矩阵:1 2 38 9 47 6 5N=5时,构成矩阵:1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9...转载 2019-05-08 13:54:04 · 447 阅读 · 0 评论