c、c++
无忧BM
这个作者很懒,什么都没留下…
展开
-
二分法查找
#include "stdafx.h"#include #include #include #include//快速查找int Find(int m[], int right, int elem){int left = 1; while (left {int mid = (left + right) / 2;if (m[mid - 1] ==原创 2015-07-25 23:48:22 · 314 阅读 · 0 评论 -
c++ 内存池的实现
1、使用内存池的原因①c/c++的内存分配(malloc或new)可能会花费时间比较多②随着时间的流逝, 会形成大量的内存碎片2、代码:#pragma once#include #include #include #define GrowValue 16struct SingleLinkNode{ SingleLin原创 2015-11-02 17:14:37 · 737 阅读 · 0 评论 -
c++ new的使用
class Student{public: Student(int x = 0){x_ = x}; ~Student(){};private: int x_;};int main(){ char s[100];//此处为栈内存,new(s)Student(2);//从数组s的首地址开始申请一个结构体所需内存 (原创 2015-10-29 19:03:59 · 592 阅读 · 0 评论 -
c++11 时间戳
chrono库包含3种类型:时间间隔duration、时间点time point和时钟clocks 1、时间段:duration、duration_cast 原型:template> class duration; //std::ratio是一个分数, p1为分子, p2为分母, 默认为1, 1; 例:在chrono命名空间下, 时、分、秒、毫秒、微原创 2015-10-20 21:20:51 · 6389 阅读 · 0 评论 -
结构体内引用数组
struct Student{public: Student(UINT32 (&usersid)[10], INT32 &l) : usersid_(usersid), len_(l) { len_ = 0; } ~Student() { }private: IN原创 2015-11-11 17:08:44 · 1542 阅读 · 0 评论 -
c++11 单例模式可变参数实现完美转发
//单例模版template class singleton{public: template static bool CreateInstance(Args&&... args) { if (m_pInstance == nullptr) m_pInstance = new T(std::forward(a原创 2015-10-26 14:00:45 · 3990 阅读 · 0 评论 -
c++11 遍历与随机数
#include #include #include #include #include //初始化vectorvoid init(std::vector &vec){ std::default_random_engine e(time(0)); //设置随机数种子 for (int i = 1; i {原创 2015-10-09 17:56:19 · 972 阅读 · 0 评论 -
C++11 std::bind与std::function
#include #include #include #include int add1(int x, int y, int z){ return x + y + z;}class Utils { public: Utils(const char* name) { strcpy_s(_n原创 2015-10-09 16:43:33 · 725 阅读 · 0 评论 -
c++11 宽字节与窄字节的相互转换
//wstring 转 string typedef std::wstring_convert> CONVER; std::wstring str = L"中国人"; std::wstring_convert> converter(new std::codecvt("CHS")); std::string narrowStr = converte原创 2015-10-20 21:17:25 · 3415 阅读 · 0 评论 -
c++ string::replace用法
本文主要针对c++中常用replace函数用法给出样例程序[cpp] view plaincopy/*用法一: *用str替换指定字符串从起始位置pos开始长度为len的字符 *string& replace (size_t pos, size_t len, const string& str); */ int mai转载 2015-07-29 17:24:28 · 7602 阅读 · 0 评论 -
libcurl库的使用
一、搭建环境1、添加依赖库 libcurld.libws2_32.libwinmm.libwldap32.lib2、添加预定义PreprocessorCURL_STATICLIB原创 2016-04-23 12:11:09 · 668 阅读 · 0 评论