自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(54)
  • 资源 (1)
  • 收藏
  • 关注

转载 lua保留n位小数方法

本文转载至http://www.cnblogs.com/pk-run/p/4444582.html1. string.format()function GetPreciseDecimal(nNum, n) if type(nNum) ~= "number" then return nNum; end n = n or

2016-08-18 21:54:39 7314

转载 设置函数环境——setfenv

文章转载至: http://www.cnblogs.com/sifenkesi/p/3843348.html 当我们在全局环境中定义变量时经常会有命名冲突,尤其是在使用一些库的时候,变量声明可能会发生覆盖,这时候就需要一个非全局的环境来解决这问题。setfenv函数可以满足我们的需求。  setfenv(f, table):设置一个函数的环境  (1)当第一个参数为一个

2016-08-18 21:15:43 424

原创 右值引用

http://www.cnblogs.com/hujian/archive/2012/02/13/2348621.html

2016-05-15 23:18:50 425

原创 multimap用法

#include #include #include #include using namespace std;int main(int argc, char** argv){ multimap mmap; mmap.insert(pair(1, 1)); mmap.insert(pair(1, 2)); mmap.insert(pair(2, 3)); multimap:

2016-05-14 22:39:19 1573

原创 list的用法,基本把所有成员试了一遍

#include #include #include using namespace std;bool RemoveOdd(const int& val){ return val % 2;}struct Desc : public binary_function{ result_type operator()(first_argument_type _Left, secon

2016-05-14 19:19:36 425

原创 单向队列queue的使用

#include #include #include using namespace std;int main(int argc, char** argv){ //deque没有迭代器,stack也没有,因此都不能排序 //deque插入元素只能从尾部插入,弹出智能从头部弹出 //创建单向队列 queue q; printf("size(): %d\n", q.size()

2016-05-14 17:23:22 1451

原创 deque的用法

#include #include #include using namespace std;class GreaterComp : public binary_function{public: result_type operator()(first_argument_type& _Left, second_argument_type& _Right) { return _

2016-05-14 17:07:54 487

原创 stack的使用

#include #include #include using namespace std;int main(int argc, char** argv){ stack s; //返回栈顶元素 //printf("top(): %d\n", s.top()); //出错 //检测栈是否为空 printf("empty(): %d\n",s.empty()); //从栈

2016-05-14 15:36:15 309

原创 stl set的用法

#include #include #include #include using namespace std;struct GreaterComp : public binary_function{ result_type operator()(first_argument_type& _Left, second_argument_type& _Rigth) { retur

2016-05-14 12:32:39 299

原创 vector的使用

#include #include #include using namespace std;int main(int argc, char** argv){ vector ivec; //想vector尾部插入元素,返回void ivec.push_back(1); ivec.push_back(11); ivec.push_back(12); //得到首元素和尾元素

2016-05-14 02:39:59 310

原创 hash_map的用法续

如果要在hash_map中把自已定义的类作为key的话要怎么做?这种情况下需要定义计算自定义的hash函数和比较自定义类的比较函数#include #include #include using namespace std;class A{public: A(int a, int b) : m_a(a), m_b(b) {} A(const A& a) { prin

2016-05-13 23:32:16 1383

原创 hash_map的使用

例子:#include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ hash_map hm; //插入元素 for (int i = 0; i < 10; i++) hm.insert(make_pair(i, i)); //正序输出 hash_map::i

2016-05-13 18:13:02 648

原创 map容器的一些方法说明

#include #include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ map dmap; dmap.insert(pair(3, 1)); dmap.insert(pair(4, 1)); dmap.insert(pair(5, 1)); dmap.inse

2016-05-12 23:38:45 1988

原创 map容器的erase用法

删除指定map中指定key的元素:#include #include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ map dmap; dmap.insert(pair(3, 1)); dmap.insert(pair(4, 1)); dmap.insert(pair

2016-05-12 23:21:52 1027

原创 map容器的insert用法总结

例子:#include #include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ map imap; map jmap; jmap[1] = 1; jmap[2] = 2; imap.insert(jmap.begin(), jmap.end()); m

2016-05-12 18:45:17 18313 1

原创 杂项

Q: #include 和 #include “...”的区别?A:前者优先在库Include路径中搜索,后者优先在项目Include路径中搜索.Q:C++中, extern "C" 在哪些情况下会被用到,作用是什么?A: 因为C++的函数重载等特征,会在编译时在函数名称前后添加修饰符(取决于实现), 这一点与C语言不兼容. 用 extern "C" 修饰后的函数

2016-05-12 01:10:43 240

转载 shared_ptr的线程安全性

shared_ptr 的线程安全级别和内建类型、标准库容器、std::string 一样,即:• 一个 shared_ptr 对象实体可被多个线程同时读取;• 两个 shared_ptr 对象实体可以被两个线程同时写入,“析构”算写操作;• 如果要从多个线程读写同一个 shared_ptr 对象,那么需要加锁;请注意,以上是 shared_ptr 对象本身的线程安全

2016-05-11 23:41:21 464

原创 shared_ptr的用法

先看一个例子:#include #include #include using namespace std;class A{public: A() { printf("A constructor\n"); } ~A() { printf("A destructor\n"); } void Print() { printf("This is A\n"); }};

2016-05-11 18:59:28 596

转载 operator new和operator delete

1. 为什么要重载 operator new ?答: 效率问题: 通常系统默认提供的分配器速度极慢, 而且分配小型对象时空间浪费严重.改变行为:默认的分配器失败时会抛出异常, 或许你想改变这种行为.2. operator new 的行为答:区分三个不同的 new:      new 操作符(new 表达式, new operator, new expression):

2016-05-11 17:02:05 1303

原创 关于指针的删除

先上一个例子:#include #include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ char* dst = "This is a str"; char* str = (char*)malloc(strlen(dst) + 1); if (str == NUL

2016-05-11 14:42:08 1835

原创 auto_ptr的使用

auto_ptr是许许多多智能指针中的一种,auto_ptr做这样一件事:拥有一个动态分配内存对象,并且在它不再需要的时候履行自动清理的职责。下面上一些使用例子:#include #include #include #include using namespace std;class D{public: D() : d(1) {} ~D() { printf("D de

2016-05-11 11:58:26 243

原创 auto_ptr作为vector的元素会出现什么情况

因为设备限制,我现在windows下进行测试,以下代码全部都在vs2013中运行过下面是例子1:#include #include #include #include using namespace std;class D{public: D() : d(1) {} ~D() { printf("D destruction\n"); } int d;};v

2016-05-11 10:46:17 2096 1

原创 模板的编译

当编译器遇到一个模板定义时,它并不生成代码。只有当我们实例化出模板的一个特定版本时,编译器才会生成代码。当我们使用(而不是定义)模板时,编译器才生成代码,这一特性影响了我们如何组织代码以及错误合适被检测到。       通常,当我们调用一个函数的时,编译器只需要掌握函数的声明。类似的,当我们使用一个类类型的对象时,类定义必须是可用的,但成员函数的定义不必已经出现。因此,我们将类定义和函数声明放

2016-05-10 16:30:29 449

转载 linux进程间通信之信号量(semaphore)

信号量函数定义如下:int semctl(int sem_id, int sem_num, int command, ...); int semget(key_t key, int num_sems, int sem_flags); int semop(int sem_id, struct sembuf *sem_ops, size_t num_sem_ops); 函数原型: i

2016-05-05 21:30:42 701

转载 pthread_cond_wait()用法分析

很久没看APUE,今天一位朋友问道关于一个mutex的问题,又翻到了以前讨论过的东西,为了不让自己忘记,把曾经的东西总结一下。先大体看下网上很多地方都有的关于pthread_cond_wait()的说明: 条件变量         条件变量是利用线程间共享的全局变量进行同步的一种机制,主要包括两个动作:一个线程等待"条件变量的条件成立"而挂起;另一个线程使"条件成立"(给出条件

2016-05-05 16:47:02 297

原创 文件的结构

http://www.hxu.edu.cn/partwebs/jisuanjixi/ctsn/dxjsjjc/kcnr/wlkj/05os/detail/5-2-5_more2.htm#

2016-05-03 14:15:04 524

原创 单向链表的冒泡排序和快速排序

冒泡排序:#include typedef struct linknode{ int value; struct linknode* next;} LinkNode;LinkNode* BubbleSort1(LinkNode* link){ int n = 0; LinkNode* p = link; while (p) { n++; p = p->ne

2016-05-01 01:50:35 728

原创 单向链表逆序问题

问题:将一个单向单向链表逆序倒转,要求O(n)的时间复杂度和O(1)的空间复杂度该问题有两种解法,一种非递归,一种是递归,代码如下:#include #include "Link.h"typedef struct linknode{ int value; struct linknode* next;} LinkNode;//递归LinkNode* ReverseLi

2016-04-29 10:58:09 288

转载 时间复杂度和空间复杂度详解

算法的时间复杂度和空间复杂度合称为算法的复杂度。1.时间复杂度(1)时间频度 一个算法执行所耗费的时间,从理论上是不能算出来的,必须上机运行测试才能知道。但我们不可能也没有必要对每个算法都上机测试,只需知道哪个算法花费的时间多,哪个算法花费的时间少就可以了。并且一个算法花费的时间与算法中语句的执行次数成正比例,哪个算法中语句执行次数多,它花费时间就多。一个算法中的语句执行次数称为语句频度或

2016-04-28 11:58:04 240

原创 七大排序算法初步实现

Sorts.h#ifndef __SORTS_H__#define __SORTS_H__//数据交换void Swap(int& a, int& b);//冒泡排序void BubbleSort(int a[], int n);//快速排序void QuickSort(int a[], int n);void QuickSortPartition1(int a[], i

2016-04-28 01:01:47 297

转载 c++之强制转换之const_cast和reinterpret_cast

const_cast,用于修改类型的const或volatile属性。const_cast (expression)该运算符用来修改类型的const或volatile属性。除了const 或volatile修饰之外, type_id和expression的类型是一样的。一、常量指针被转化成非常量的指针,并且仍然指向原来的对象;二、常量引用被转换成非常量的引用,并且仍然指向原来的

2016-04-20 15:23:29 2382

原创 c++强制转换之dynamic_cast

dynamic_cast(expression)用法:该运算符把expression转换成type-id类型的对象。Type-id必须是类的指针、类的引用或者void*;如果type-id是指针类型,那么expression也必须是一个指针,如果type-id是一个引用,那么expression也必须是一个引用。      dynamic-cast运算符可以在执行期间决定真正的类型。如果下

2016-04-20 02:44:45 4370

原创 C++强制转换之static_cast

static_cast用法:static_cast(expression)简介:该运算符把expression转换为type_id类型,但没有运行时类型检查来保证转换的安全性。主要有以下几种用法:1. 用于类层次结构中基类和派生类之间指针或引用的转换:进行上行转换是安全的,进行下行转换时是不安全的2. 用于基本数据类型之间的转换3. 把空指针转换成目标类型的空指针

2016-04-19 23:43:44 861

转载 关于C++中的友元函数的总结

1.友元函数的简单介绍1.1为什么要使用友元函数在实现类之间数据共享时,减少系统开销,提高效率。如果类A中的函数要访问类B中的成员(例如:智能指针类的实现),那么类A中该函数要是类B的友元函数。具体来说:为了使其他类的成员函数直接访问该类的私有变量。即:允许外面的类或函数去访问类的私有变量和保护变量,从而使两个类共享同一函数。实际上具体大概有下面两种情况需要使用友元函数:(1)运算

2016-04-19 18:02:36 262

原创 类的const限定符

例子1:class A{public: A() {} ~A() {}public: int Test() const { printf("const\n"); return 0; } int Test() { printf("non const\n"); return 0; } static int Change() const //这个定义

2016-04-19 17:50:39 352

原创 c++类的拷贝构造函数、隐式转换、重载的赋值操作符的一些分析和实例

1. 隐式转换和拷贝构造之间的一点实例分析#include #include #include #include using namespace std;class A{public: A(int i): m_a(i) { printf("constructor\n"); } A(const A &a) { printf("copy construct

2016-04-18 12:05:11 589

原创 关于运算符重载

Q:不能重载的运算符哪几个?A:   . (成员访问运算符)   .* (成员指针访问运算符)   ∷ (域运算符)    sizeof (长度运算符)    ?: (条件运算符)Q:C++中重载输出运算符,为什么要返回引用?A:因为ostream不能复制,所以必须返回引用.Q:C++关键字的explicit的作用?A:   在C++中,expl

2016-04-17 23:32:42 398

转载 C/C++ Volatile关键词深度剖析

1    背景    12    Volatile:易变的    12.1    小结    23    Volatile:不可优化的    33.1    小结    44    Volatile:顺序性    44.1    happens-before    64.2    小结    75    Volatile:Java增强

2016-04-17 17:37:50 684

原创 RVO(Return Value Optimization)和NRVO(Named Return Value Optimization)

中文解释:RVO:返回值优化                    NRVO:具命返回值优化具体示例如下:#include class A{public: A(int i): m_a(i) { printf("constructor\n"); } A(const A &a) { printf("copy constructor\n"); m_a = a

2016-04-17 15:20:27 1290

原创 c++类构造函数、析构函数与虚函数之间的那点小事

Q:类的构造函数是否可以是虚函数?A:不可以。      首先,设置后编译出错,语法上c++并不允许把类的构造函数声明为虚函数;      其次,抛开语法层面,类对象构造的时候是按照继承层次从上至下开始构造。创建一个类对象的时候是先分配整个类需要的存储空间,然后开始执行构造函数,举个简单的例子:class A{public: A() {} virtual void

2016-04-16 23:08:46 332

Windows网络编程(第二版免费).pdf

windows网络编程的经典书籍,适合网络编程初学者

2013-10-20

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除