
c++
chent86
在校大学生
展开
-
如何构建一个简单链表
如何构建一个简单链表: 链表的创建,单个插入,单个删除,整体删除原创 2017-03-21 20:56:15 · 20968 阅读 · 0 评论 -
windows下c++如何读取主机名
#include <windows.h>#include <tchar.h>#include <stdio.h>#include <string>#include <iostream>using namespace std;int main() { TCHAR buf[MAX_COMPUTERNAME_LENGTH + 2]; DWORD buf_size; buf原创 2017-09-03 10:46:38 · 3809 阅读 · 0 评论 -
c++实现链表归并排序
一. 定义节点struct node { int data; node* next; node(int data = 0, node* next = NULL) :data(data), next(next) {}};二. 归并排序主体结构void mergesort(node*& head) { if(head->next) { node* mid = cut(head原创 2017-11-02 10:11:44 · 3013 阅读 · 0 评论 -
c++实现快速排序
主体结构void quicksort(int low, int high) { if(low < high) { int mid = partition(low, high); quicksort(low, mid-1); quicksort(mid+1, high); }}将数组中的段再处理成: 左半边的数比pivot小,右半边的数比pivot大 处理到原创 2017-11-02 11:49:47 · 265 阅读 · 0 评论 -
linux下gtest&gmock下载
按以下步骤执行即可 这样便下载完成了!原创 2017-07-27 16:19:44 · 1645 阅读 · 0 评论 -
stl map的用法
#include <iostream>#include <map>using namespace std;int main() { map<int,int> tmp; //构造函数, 前一个类型为键的类型,后一个为值的类型 tmp.insert(pair<int,int>(3,1)); tmp.insert(pair<int,int>(2,2));原创 2018-01-06 09:12:01 · 221 阅读 · 0 评论 -
stl set 的用法
#include #include using namespace std;int main() { setint> tmp; setint>::iterator i; tmp.insert(3); tmp.insert(2); //插入 tmp.insert(1); tmp.insert(3); for(i = tmp.beg原创 2018-01-06 09:23:33 · 254 阅读 · 0 评论 -
stl map 使用结构体作为键
#include #include #include using namespace std;struct package{ int id; string data; bool operatorconst package& tmp) const{ if(this->id < tmp.id) return true; //原创 2018-01-06 09:43:13 · 1214 阅读 · 0 评论 -
stl set 使用结构体
#include #include #include using namespace std;struct package{ int id; string data; bool operatorconst package& tmp) const{ if(this->id < tmp.id) return true; /原创 2018-01-06 09:51:37 · 3149 阅读 · 0 评论 -
c++优先队列使用结构体
#include #include #include using namespace std;struct package{ int id; string data;};bool operator<(package a, package b) { return a.id < b.id;} //自定义排序规则int main() { pr原创 2018-01-06 10:09:41 · 8641 阅读 · 0 评论 -
map自定义排序规则
#include #include #include using namespace std;struct comp{ bool operator()(const string &a, const string &b) const { if(a.length() == b.length()) return a < b; i原创 2018-01-06 17:22:14 · 3895 阅读 · 0 评论 -
c++实现堆排序
堆排序虽然是在数组上进行排序, 但实际上它使用了层次遍历的二叉树的思想。一、 排序的整体结构void sort(int num) { build(num); for(int i = num-1; i > 0; i--) { int current = array[i]; array[i] = array[0]; inser原创 2017-11-03 19:34:55 · 441 阅读 · 0 评论 -
makefile模板
CC := g++FLAGS := -std=c++11 -wINC_DIR := includeSRC_DIR := srcBUILD_DIR := buildBIN_DIR := binINCLUDE := -I./$(INC_DIR)$(BIN_DIR)/main: $(BUILD_DIR)/a.o $(BUILD_DIR)/b.o $(BUILD_DIR)/main.o...原创 2018-11-02 14:14:25 · 169 阅读 · 0 评论 -
stl map 基本用法
构造函数map<int, string> m_map;map<int, string> m_map = {make_pair(1, "test")};插入m_map[0] = "test";m_map.insert(pair<int,string>(1, "test"));m_map.insert(map<int, string>::value_type (1, "test"));删除 map原创 2017-09-27 10:27:17 · 782 阅读 · 0 评论 -
windows下如何使用c++ sqlite3
1. 首先, 安装sqlite3到官网下载sqlite-tools-win32-*.zip和 sqlite-dll-win32-*.zip这两个压缩文件(选择适合自己系统的, 我下载的是sqlite-dll-win32-x86-3200000.zip和sqlite-tools-win32-x86-3200000.zip) 下载到自己觉得合适的地方, 解压缩。2. 添加路径(可选)为了方便使用数据库,原创 2017-08-14 11:41:52 · 3616 阅读 · 0 评论 -
如何避免c++中using语句造成的名称冲突
如何避免c++中using语句造成的名称冲突使用如:using namespace std; 的using 语句确实很简便,但是这将该命名空间的所有名称都调用出来了,这就增大了名称冲突的可能性。所以有些程序员建议在头文件中不要使用using 语句,执行文件可以酌情使用,并建议使用using std::cin; 然而这样一来程序就变得复杂很多,还有一种方法,就是将using namespace std原创 2017-02-23 11:38:01 · 893 阅读 · 0 评论 -
c++STL pair的基本用法
本文提供构造pair的三种简单方法的例子#include <iostream>using namespace std;int main() { pair<int, int> a; a.first = 0; a.second = 1; pair<int, int> b(1, 2); pair<int, int> c; c = make_pair(2,3); cout原创 2017-07-30 13:18:11 · 416 阅读 · 0 评论 -
linux下c++如何输入不回显且输入不用回车
参考链接下面代码实现的是输入一个小写字母只能看到大写字母#include <stdio.h>#include <termios.h> #include <unistd.h> #include <iostream>using namespace std;int main(void){ char c; static struct termi原创 2017-07-30 13:28:32 · 3340 阅读 · 0 评论 -
c++switch的基本用法
switch只能接受整型和字符型:整型:#include <iostream>using namespace std;int main(void){ int a; while(true) { cin >> a; switch(a) { case 1: cout << "hi" << endl; break;原创 2017-07-30 15:08:38 · 62461 阅读 · 14 评论 -
c++11多线程以及上锁的简单例子
多线程, 简单的理解就是让我们可以同时做多件事情, 以下为简单例子.#include <iostream>#include <thread>using namespace std;void first() { cout << "do one thing" << endl;} void second() { cout << "do another thing" <<原创 2017-07-29 19:05:30 · 1887 阅读 · 0 评论 -
c++ STL vector如何删除
#include <iostream>using namespace std;#include <vector>int main(){ std::vector<int> a = {1, 2, 3, 4}; for(auto i = a.begin(); i != a.end(); ) if(*i == 3) i = a.erase(i); else原创 2017-07-30 19:22:53 · 390 阅读 · 0 评论 -
linux下c++sleep函数
sleep() 秒级usleep() 微秒级#include <iostream>using namespace std; #include <unistd.h>int main(){ while(1) { cout << "hello" << endl; //sleep(1); usleep(100000)原创 2017-07-30 19:38:04 · 83132 阅读 · 4 评论 -
c++随机数简单用法
附上简单例子#include <ctime>#include <iostream>#include <cstdlib>using namespace std;int main() { srand(time(0)); int num; for(int i=0; i<10; i++){ num=rand() % 5;...原创 2017-07-30 20:52:34 · 270 阅读 · 0 评论 -
linux下如何通过rabbitmq进行简单的电脑间通信
SimpleAmqpClient中channel的构造函数是这样的:static ptr_t AmqpClient::Channel::Create(const std::string & host = "127.0.0.1", int port = 5672,原创 2017-08-01 00:41:57 · 1257 阅读 · 0 评论 -
linux下安装c++ rabbitmq客户端SimpleAmqpClient
linux下安装SimpleAmqpClient(注:本文以 github为基础,并加以说明,额 …就是菜鸟教程)安装boost-1.47.0下载官网 在官网找到适合的版本下载即可 打开目录后./bootstrap.sh./bjam大概需要运行5-10分钟安装rabbitmq-cgithub地址git clone https://github.com/alanxz/rabbitmq-c原创 2017-07-25 14:47:55 · 3848 阅读 · 2 评论 -
linux下rabbitmq SimpleAmqpClient客户端的使用的简单例子
本文将提供一个使用rabbitmq SimpleAmqpClient客户端的简单的例子编译方法原创 2017-07-28 19:00:19 · 4600 阅读 · 0 评论 -
c++文件读写的简单例子
读取文件逐条读取#include <string>#include <iostream>#include <fstream>using namespace std;int main() { std::ifstream file1("1.txt"); //此处的字符串为文件的路径 string my_read; while(getline(file1, my原创 2017-08-16 10:36:47 · 1488 阅读 · 0 评论 -
c++获得string的子串
使用stirng的substr函数, 其中第一个参数是起始位置, 第二个参数是子串的长度#include <iostream>#include <string>using namespace std;int main() { string a = "20170816"; string b = a.substr(0,4); string c = a.substr(4,2)原创 2017-08-16 13:32:13 · 20533 阅读 · 0 评论 -
c++使用sqlite3的例子
这个代码可在windows下运行,不过需要下载库文件, 在上一篇博客中有提到如何下载 .若是在linux下运行代码, 下载好sqlite3后(linux下简单得多), 将头文件”sqlite3.h” 改成#include <stdio.h>#include <string>#include <iostream>#include "sqlite3.h" using namespace std;原创 2017-08-15 10:40:20 · 4461 阅读 · 0 评论 -
c++ 右值引用
首先,什么是左值、右值?左值是能出现在等号左边和右边的变量,右值是只能出现在等号右边的变量(或表达式)。左值引用为 & , 而右值引用为 &&。那么为什么需要右值引用呢?主要是为了处理c++临时对象的低效的问题,使用右值引用可以减少不必要的拷贝构造。举个例子:#include <iostream>using namespace std;...原创 2019-02-17 21:05:17 · 202 阅读 · 0 评论