
C/C++
zlQ_
这个作者很懒,什么都没留下…
展开
-
C/C++--参数传递
const int *p; 指针常量,p指针所指向的内容不允许修改 int* const p; 限制p本身的内容不允许修改const int* const p; 本身内容和所指向的内容都不允许修改原创 2013-04-01 23:58:43 · 729 阅读 · 0 评论 -
c/c++--指针数组和数组指针的区别
指针数组:array of pointers,即用于存储指针的数组,也就是数组元素都是指针(整形数组表示一个数组里面的元素都是整形数,同理指针数组表示一个数组里的元素都是指针)数组指针:a pointer to an array,即指向数组的指针举例:int* a[4] 指针数组 表示:数组a中的元素都为int型指针原创 2015-03-10 12:59:05 · 882 阅读 · 0 评论 -
C/C++--初始化列表
一点小总结,对于类成员,最好是放在初始化列表里进行初始化,优点如下:#include "stdafx.h"#include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ class Class1 { public: int m_iValue; Class1()// 无参构造原创 2015-03-24 19:28:17 · 999 阅读 · 0 评论 -
C/C++--类占用内存的大小计算
一个类占用多少内存,看下面代码:// TestVS2012.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ class Class1{}; class Class2 { int m_iValue;原创 2015-03-24 19:51:44 · 2570 阅读 · 0 评论 -
C/C++--strcpy函数实现
注:考虑内存重叠问题#include "stdafx.h"#include #include char* myStrCpy(char *pDst, const char *pSrc){ assert(NULL != pDst); assert(NULL != pSrc); char *pDT = pDst; size_t iCount = strlen(pSrc) +原创 2015-04-13 15:42:19 · 1575 阅读 · 0 评论 -
C/C++--memcpy函数实现
注:没有考虑内存重叠的情况#include "stdafx.h"#include #include void* myMemCpy(void *pDst, const void *pSrc, size_t iCount){ assert(NULL != pDst); assert(NULL != pSrc); char *pDT = (char*)pDst; cons原创 2015-04-13 15:24:52 · 2430 阅读 · 0 评论 -
C/C++--strcpy函数实现
注:没有考虑到内存重叠的情况#include "stdafx.h"#include #include char* myStrCpy(char *pDst, const char *pSrc){ assert(NULL != pDst); assert(NULL != pSrc); char *pDT = pDst; while ((*pDT++ = *pSrc++原创 2015-04-13 15:14:38 · 1449 阅读 · 0 评论 -
C/C++--memmove函数实现
#include "stdafx.h"#include #include void* myMemMove(void *pDst, const void *pSrc, size_t iCount){ assert(NULL != pDst); assert(NULL != pSrc); char *pDT = (char*)pDst; const char *pST = (con原创 2015-04-13 15:28:53 · 2293 阅读 · 0 评论 -
C/C++--strlen函数实现
#include "stdafx.h"#include #include //递归实现size_t myStrCpy(const char *pStr){ assert(NULL != pStr); if ('\0' != *pStr) { return 1 + myStrCpy(++pStr); } else { return 0; }}//非递归实现/原创 2015-04-13 15:50:44 · 3332 阅读 · 0 评论 -
C/C++--char *s 和 char s[] 的区别
原文地址:http://duanhengbin.iteye.com/blog/1706635转载 2014-09-15 12:25:34 · 4692 阅读 · 0 评论 -
C/C++--C++获取目录下的文件列表
#include #include #include #include #include #include #include using namespace std; void getFiles( string, vector& );int main() { vector files;转载 2014-08-02 16:40:49 · 2182 阅读 · 0 评论 -
C,C++--用IOS成员格式化输入和输出
C,C++--用IOS成员格式化输入和输出原创 2013-08-21 11:27:12 · 1612 阅读 · 0 评论 -
C,C++ ---结构体指针初始化
结构体:struct ScatteredBullet { DoubleBullet *pBullet1; DoubleBullet *pBullet2; DoubleBullet *pBullet3; };初始化: ScatteredBullet *pScatteredBullet = (struct ScatteredBullet*)malloc(sizeo原创 2013-11-23 11:40:29 · 8429 阅读 · 2 评论 -
C/C++--字符串切割及去两端空格
#includeusing namespace std;字符串切割 int DataHelper::split( const string &str, vector &result, const string &sep ) { if (str.empty()) { return 0; }翻译 2014-03-22 12:39:20 · 2102 阅读 · 0 评论 -
C/C++--模板类实现.h和.cpp分离
用VS2012创建控制台工程代码如下:原创 2014-06-24 15:27:15 · 2385 阅读 · 0 评论 -
C/C++--set排序
// TestVS2012.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include struct Test{ std::string name; int age;};class CustomSort{public: bool operator()(const Test &t1, con原创 2014-07-22 14:23:26 · 2318 阅读 · 0 评论 -
C/C++--set存储结构体
set所存储的内容需要可比较的,原创 2014-06-14 13:29:53 · 6150 阅读 · 4 评论 -
C/C++--STL中list,vector,deque,map,set区别、联系和使用场景
原谅地址:http://www.lifecrunch.biz/archives/202vector和built-in数组类似,它拥有一段连续的内存空间,并且起始地址不变,因此它能非常好的支持随即存取,即[]操作符,但由于它的内存空间是连续的,所以在中间进行插入和删除会造成内存块的拷贝,另外,当该数组后的内存空间不够时,需要重新申请一块足够大的内存并进行内存的拷贝。这转载 2014-06-16 20:46:03 · 4312 阅读 · 0 评论 -
C/C++--定义二维数组及二维数组的传递
// TestVS2012.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #define ROW 4#define COL 4void printValue(int **pValue, int row, int col){ for (int r = 0; r < row; r++) { for (int c = 0;原创 2014-07-08 16:38:25 · 4458 阅读 · 0 评论 -
C/C++--strcmp函数实现
#include "stdafx.h"#include #include int myStrCmp(const char *pStr1,const char *pStr2) { while(NULL != pStr1 && NULL != pStr2) { while(*pStr1++ == *pStr2++) { if('\0' == *pStr原创 2015-04-13 16:33:35 · 1785 阅读 · 0 评论