03 2007 档案

malloc calloc realloc
摘要:1calloc(), malloc(), realloc(), free() 2 3 4void *calloc(size_t nobj, size_t size); 5分配足够的内存给nobj个大小为size的对象组成的数组, 并返回指向所分配区域的第一个字节的指针; 6若内存不够,则返回NULL. 该空间的初始化大小为0字节. 7char *p = (char *) calloc(10... 阅读全文

posted @ 2007-03-27 18:15 Edward Xie 阅读(250) 评论(0) 推荐(1)

VC数据类型命名(常用)
摘要:c win * const *char CHAR LPSTR LPCSTRwchar_t WCHAR LPWSTR LPCWSTR | ... 阅读全文

posted @ 2007-03-26 21:34 Edward Xie 阅读(130) 评论(0) 推荐(0)

sprintf相关
摘要:#include #include #include int CDECL MessageBoxPrintf(TCHAR *szCaption, TCHAR *szFormat,){ TCHAR szBuffer[1024]; va_list pArgLIST; va_start(pArgLIST, szFormat); _vsntprintf(szBuffer, sizeof(szBuff... 阅读全文

posted @ 2007-03-26 21:34 Edward Xie 阅读(414) 评论(0) 推荐(0)

sun lession1
摘要:DWORD 32位 *********************************************************一类变量 每位(bit)对应某特性 加入某类特性:用或(|)操作符 去处某特性:对该量取反(~)再与原值相与(&) ********************************************************* 设计 WNDCLA... 阅读全文

posted @ 2007-03-26 21:33 Edward Xie 阅读(127) 评论(0) 推荐(0)

MFC框架
摘要:讲述MFC AppWizard的原理与MFC程序框架的剖析。AppWizard是一个源代码生成工具,是计算机辅助程序设计工具,WinMain在MFC程序中是 如何从源程序中被隐藏的,theApp全局变量是如何被分配的,MFC框架中的几个类的作用与相互关系,MFC框架窗口是如何产生和销毁的,对窗口类的 PreCreateWindow和OnCreate两个函数的着重分析,Windows窗口与C++中的... 阅读全文

posted @ 2007-03-26 21:32 Edward Xie 阅读(2892) 评论(0) 推荐(0)

VC数据类型命名(常用)
摘要:c win * const *char CHAR LPSTR LPCSTRwchar_t WCHAR LPWSTR LPCWSTR | ... 阅读全文

posted @ 2007-03-24 01:11 Edward Xie 阅读(81) 评论(0) 推荐(0)

文件IO随机访问例子
摘要:#include // not required by most systems#include #include #include // (or stdlib.h) for exit()const int LIM = 20;struct planet{ char name[LIM]; // name of planet double populatio... 阅读全文

posted @ 2007-03-24 01:05 Edward Xie 阅读(230) 评论(0) 推荐(0)

IO fio
摘要:1>基本io////////////////////////////////////////////////////////////////////////////////////////////////ofstream fout; //写出流fout.open("file.txt"); ofstream fout("file.txt");*************... 阅读全文

posted @ 2007-03-24 01:00 Edward Xie 阅读(374) 评论(0) 推荐(0)

IO cin
摘要:1>重载>>操作符//////////////////////////////////////////////////////////////////////////////////////////////istream & operator>>(…) 2>可选输入格式/////////////////////////////////////////////////////////////... 阅读全文

posted @ 2007-03-22 04:14 Edward Xie 阅读(231) 评论(0) 推荐(0)

IO cout
摘要:1>重载其他ostream方法///////////////////////////////////////////////////////////////////////////////////////////////////////////*1*/ostream & put(char) //输出一个字符,返回一个ostream对象//ep:cout.put('a').put('65') &... 阅读全文

posted @ 2007-03-21 22:49 Edward Xie 阅读(436) 评论(0) 推荐(0)

一个关于静态成员的链表模型
摘要:jamesji----->colin----->marry----->NULL0012ff28 0012ff4c 00371bb8 point[0012ff28] jamesji----->colin----->NULL0012ff28 0012ff4c point[0012ff28] /////////////////////////////////////////... 阅读全文

posted @ 2007-03-19 18:00 Edward Xie 阅读(141) 评论(0) 推荐(0)

类的静态数据成员 和 成员函数 说明
摘要:类的静态成员是属于类的而不是属于哪一个对象的,所以静态成员的使用应该是类名称加域区分符加成员名称的ep: int ClassName::val=20;(初始化)且写在主函数调用前 不能在类声明中初始化 静态成员函数的特性类似于静态成员的使用,同样与对象无关,调用方法为类名称加域区分符加成员函数名称 静态成员函数由于与对象无关系,所以在其中是不能对类的普通成员进行直接操作的 静态成员函数与普通成... 阅读全文

posted @ 2007-03-19 18:00 Edward Xie 阅读(205) 评论(0) 推荐(0)

C_C++头文件
摘要:C/C++头文件一览C、传统 C++ #include //设定插入点 #include //字符处理 #include //定义错误码 #include //浮点数处理 #include //文件输入/输出 #include //参数化输入/输出 #include //数据流输入/输出 #include //定义各种数据类型最... 阅读全文

posted @ 2007-03-18 19:06 Edward Xie 阅读(179) 评论(0) 推荐(0)

STL 使用STL实例
摘要://usealgo.cpp -- using several STL elements#include #include #include #include #include #include #include #include using namespace std; char toLower(char ch) { return tolower(ch); } //转字符string & ToL... 阅读全文

posted @ 2007-03-18 19:06 Edward Xie 阅读(1295) 评论(0) 推荐(0)

STL 算法
摘要:STL算法分类*非修改式序列操作 (ep:find() for_each())*修改式序列操作 (ep:transform() random_shuffle() copy())*排序和相关操作 (ep:sort())(以上被包含在 #include ) *通用数字运算 (以上被包含在 #include ) 复制版本 函数名后面加 _copy 将函数应用与容... 阅读全文

posted @ 2007-03-18 18:58 Edward Xie 阅读(206) 评论(0) 推荐(0)

STL 函数对象
摘要:函数符************************************************************生成器(generator)不用参数就可以调用的函数符一元函数(unary funcation)二元函数(binary funcation)返回bool值的一元函数是断言(predicate)返回bool值的一元函数是二元断言(predicate)/////////////... 阅读全文

posted @ 2007-03-18 17:00 Edward Xie 阅读(1293) 评论(0) 推荐(0)

STL 容器概念(联合容器)
摘要:联合容器//////////////////////////////////////////////#include set multiset #include map multimap值与关键字联合在一起 提供了队元素的快速访问 允许插入新元素 但不允许指定插入位子 **********************************************************... 阅读全文

posted @ 2007-03-18 15:41 Edward Xie 阅读(529) 评论(0) 推荐(0)

STL 容器概念(序列)
摘要:序列////////////////////////////////////deque list queue priority_queue stack vector序列要求至少是正向迭代器 保证特定顺序排序 不会再两次迭代发生变化X a(n,t) 初始化为n个tX (n,t) 匿名序列初始化为n个tX a (i,j) 初始化为[i,j)内容X (i,j... 阅读全文

posted @ 2007-03-18 02:08 Edward Xie 阅读(185) 评论(0) 推荐(0)

STL find算法
摘要:typedef double * iteratoriterator find_dr(iterator begin,iterator end,const double & dd){ iterator it; for (it=begin;it!=end;it++) if (* it==dd) return it; return end;} 阅读全文

posted @ 2007-03-18 00:24 Edward Xie 阅读(605) 评论(0) 推荐(0)

STL 迭代器
摘要:容器种类::iterator 对象名 容器种类::const_iterator 对象名 容器种类::reverse_iterator 对象名 //反向 容器种类::const_reverse_iterator 对象名 //反向 //*#include *// ostream_iterator 对象名(使用的输出流,"发送去每个数据后分隔符");(ostream_iterator... 阅读全文

posted @ 2007-03-17 23:40 Edward Xie 阅读(339) 评论(0) 推荐(0)

STL 5类迭代器概念
摘要:功能 输入 输出 正向 双向 随机访问 解除引用读入 y n y y y 解除引用写入 n y y y y 固定可重复排序 n n y y ... 阅读全文

posted @ 2007-03-17 21:27 Edward Xie 阅读(177) 评论(0) 推荐(0)

STL 对矢量的其他操作
摘要:for_each() 可以替代要显示用iterator的循环 ep:vector::iterator pr;for(pr=books.bgein();pr!=books.end();pr++) ShowReview(*pr);************************************************************for_each(books.begein(... 阅读全文

posted @ 2007-03-17 20:04 Edward Xie 阅读(131) 评论(0) 推荐(0)

STL 对矢量可执行操作
摘要:size()-------------返回容器中元素个数 swap()-------------交换两个容器内容 begin()------------返回指向容器第一个元素的迭代器 end()--------------返回一个超尾迭代器 rbegin()-----------返回一个超尾反向迭代器 rend()-------------返回指向容器第一个元素的反向迭代器 maxsize()--... 阅读全文

posted @ 2007-03-17 18:02 Edward Xie 阅读(188) 评论(0) 推荐(0)

重载运算符 ++ 和 --
摘要:如何重载增量运算符 ++ 和 -- 运算符++和—有前置和后置两种形式,如果不区分前置和后置,则使用operator++( )或operator--( )即可;否则,要使用operator++( )或operator--( )来重载前置运算符,使用operator++(int)或operator--(int)来重载后置运算符,调用时,参数int被传递给值0。如下列程序段: #include ... 阅读全文

posted @ 2007-03-17 16:36 Edward Xie 阅读(8414) 评论(0) 推荐(0)

MFC框架
摘要: 阅读全文

posted @ 2007-03-15 18:16 Edward Xie 阅读(302) 评论(0) 推荐(0)

this指针
摘要:是那个类构造的对象 这个this指针就是指向那个对象的 比如是派生类构造的对象 this 就是指向派生类的 在A的构造函数中使用了this 但是用其派生类构造对象 所以(有父才有子,先构造个基类)但this指向的还是派生类滴对象////////////////////////////////////////////////////////////////////#include using n... 阅读全文

posted @ 2007-03-15 17:54 Edward Xie 阅读(138) 评论(0) 推荐(0)

c语言 文件操作
摘要:FILE文件指针结构 ****************************************************fopen("文件名","使用文件方式")(返回值应赋给一个文件指针)使用文件方式: “rt” 只读 打开一个文本文件,只允许读数据 “wt” 只写 打开或建立一个文本文件,只允许写数据 “at” 追加 打开一个文本文件,并在文件末尾写数据... 阅读全文

posted @ 2007-03-15 12:48 Edward Xie 阅读(192) 评论(0) 推荐(0)

auto_ptr类
摘要:要包含auto_ptr类 需包含头文件#include templateclass auto_ptr{public: explicit auto_pst(X* p=0) throw(); …}; ep:auto_ptr pd (new double); new double出为一个地址或NULL ep2:auto_ptr构造函数是'显式'的因此不存从指针到auto_ptr对象隐式转... 阅读全文

posted @ 2007-03-14 16:35 Edward Xie 阅读(172) 评论(0) 推荐(0)

string类 其他功能与注意
摘要:c_str() 返回一个c风格字符串***********************************************************string filename;cout>filename;ofstream fout; fout.open(filename.c_str()); ///////////////////////////////... 阅读全文

posted @ 2007-03-14 16:01 Edward Xie 阅读(144) 评论(0) 推荐(0)

string类 方法
摘要:可以进行string对象或和c风格字符串之间'' '==' '!='比较************************************************************* size() length() 返回字符串长度************************************************************* find()//*pos都表示... 阅读全文

posted @ 2007-03-14 00:38 Edward Xie 阅读(294) 评论(0) 推荐(0)

string类 输入
摘要:getline(cin,str);******************************** getline(cin,str,':');********************************* /////////////////////////////////////////////////////////////////////////////////////////////... 阅读全文

posted @ 2007-03-13 22:39 Edward Xie 阅读(241) 评论(0) 推荐(0)

string类 构造函数
摘要:string (const char * s);string (size_type n,char c);string (const char * s,size_type n);string (const string & str,size_tpye n=npos);string ();templatestring(Iter begin,Iter end); string::npos (通常为最大... 阅读全文

posted @ 2007-03-13 22:20 Edward Xie 阅读(6060) 评论(0) 推荐(0)

一个简单的窗口程序
摘要:#include #include LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lPar... 阅读全文

posted @ 2007-03-12 19:26 Edward Xie 阅读(165) 评论(0) 推荐(0)

lession1
摘要:DWORD 32位 *********************************************************一类变量 每位(bit)对应某特性 加入某类特性:用或(|)操作符 去处某特性:对该量取反(~)再与原值相与(&) ********************************************************* 设计 WNDCLA... 阅读全文

posted @ 2007-03-12 19:25 Edward Xie 阅读(183) 评论(0) 推荐(0)

强类型转换操作符
摘要:dynamic_cast:Type *pp=dynamic_cast(pt);(pt为某个类的指针)(Type要是(*pt)的直接或间接基类 否则返回一个0即空指针) const_cast:实现const和volatile转换 ep:const High * pbar=&bar; Hight * pb=const_cast(pbar); //ok删除const标签 Low * pl=c... 阅读全文

posted @ 2007-03-11 01:59 Edward Xie 阅读(187) 评论(0) 推荐(0)

RTTI
摘要:1>dynamic_cast Type *pp=dynamic_cast(pt);(pt为某个类的指针)(Type要是(*pt)的直接或间接基类 否则返回一个0即空指针) 2>typeid操作符和type_info类 typeid操作符返回一个type_info类 typeid(ClassName)==typeid(*pp) (pp为某类型指针 等返回true 不等返回false)(pp为... 阅读全文

posted @ 2007-03-11 01:43 Edward Xie 阅读(93) 评论(0) 推荐(0)

异常 异常迷失方向及注意事项
摘要:1>未捕获异常 未捕获异常不会直接导致程序终止 会先调用terminate()->terminate()调用abort() 可以指定terminate()调用的函数而修改用set_terminate()函数//set_terminate() 和 terminate()都在头文件#include 中 set_terminate(): typedef void (*terminate_handler)... 阅读全文

posted @ 2007-03-11 01:25 Edward Xie 阅读(182) 评论(0) 推荐(0)

异常 类和继承
摘要://///////////////////////////////////////////sales.h///////////////////////////////////////////// sales.h -- exceptions and inheritance#include #include class Sales{public: enum {MONTHS = 12}; // ... 阅读全文

posted @ 2007-03-11 00:50 Edward Xie 阅读(183) 评论(0) 推荐(0)

异常 bad_alloc 与new
摘要://////////////////////////////////////////////////////////// newexcp.cpp -- the bad_alloc exception/////////////////////////////////////////////////////////#include #include #include using namespace s... 阅读全文

posted @ 2007-03-11 00:24 Edward Xie 阅读(1125) 评论(0) 推荐(0)

异常 exception类
摘要:exception类 该类通常作为异常的基类 其中有一个what()虚函数 可被重新定义ep:#include class bad_mean : public exception{public: vitrual const char * what() {return "bad bad vad";}}; 如不想用不同方法处理派生而来的异常 则可以在一个catch块中捕获 catch (excep... 阅读全文

posted @ 2007-03-11 00:12 Edward Xie 阅读(375) 评论(0) 推荐(0)

异常 堆栈解退
摘要://函数出现异常而终止,程序将释放堆栈重内存,并一直向上释放,只到找到一个try块中的返回地址 //重新引发异常 将捕获的异常继续传回上一个try块 ///////////////////////////////////////////////////exc_mean.h/////////////////////////////////////////////////#include clas... 阅读全文

posted @ 2007-03-10 23:36 Edward Xie 阅读(937) 评论(0) 推荐(0)

异常机制
摘要:异常机制 try块(可能异常的代码块) catch块(捕获异常) throw块(引发异常) //////////////////////////////////////////error.cpp/////////////////////////////////////////#include double hmean(double a,double b); int main(void){ us... 阅读全文

posted @ 2007-03-10 20:21 Edward Xie 阅读(127) 评论(0) 推荐(0)

异常 abort()与返回错误码
摘要:1>调用函数终止程序 #include #include //for abort(); or exit(x); x为0正常终止 非0非正常终止double hmean (double a,double b); int main(void){ double x,y,z; std::cout>x>>y) { z=hmean(x,y); std::cout: "; } std::... 阅读全文

posted @ 2007-03-10 14:10 Edward Xie 阅读(536) 评论(0) 推荐(0)

模板中嵌套
摘要://///////////////////////////////////////////////////// queuetp.h -- queue template with a nested class////////////////////////////////////////////////////#ifndef QUEUETP_H_#define QUEUETP_H_ template... 阅读全文

posted @ 2007-03-09 16:06 Edward Xie 阅读(210) 评论(0) 推荐(0)

友元类 友元成员函数
摘要:友元类 ///////////////////////////////////////////// tv.h///////////////////////////////////////////#ifndef TV_H_#define TV_H_ class Tv{public: friend class Remote; enum {off,on}; enum {MinVal,Ma... 阅读全文

posted @ 2007-03-09 12:10 Edward Xie 阅读(1359) 评论(0) 推荐(0)

小注意
摘要:需要const T & item T为 const char * 即是const const char * & item 时候 用模板 阅读全文

posted @ 2007-03-07 07:57 Edward Xie 阅读(104) 评论(0) 推荐(0)

类模板 友元
摘要:3类友元 1>非模板友元 2>约束模板友元(外部声明模板) 3>非约束模板友元(内部声明模板) 1>非模板友元 这类友元不是成员函数,所以可能需要用到的实例化 都要有定义(函数重载)///////////////////////////////////////////////////////////// frnd2tmp.cpp -- template class with non-t... 阅读全文

posted @ 2007-03-07 07:51 Edward Xie 阅读(467) 评论(0) 推荐(0)

类模板 模板做为参数
摘要:class Crab 类声明中调用Thing s1; // 将T 设为 intThing s2; // 将T 设为 double //***************************************************// Crab nebuba; //Stack必须式模板类 /////////////////... 阅读全文

posted @ 2007-03-07 07:31 Edward Xie 阅读(343) 评论(0) 推荐(0)

类模板 成员模板
摘要:可以把类模板 函数模板 作为类的成员 可以在类声明外定义:(如下)#include using std::cout;using std::endl; template class beta{private: template //class class hold; hold q; // template object hold n; ... 阅读全文

posted @ 2007-03-07 07:17 Edward Xie 阅读(317) 评论(0) 推荐(0)

类模板 特例化
摘要:1.隐式实例化ep:ArrayTp stuff; ep:ArrayTp *pp; //第二条才被实例化生成类定义,且在编译器需要对象前不会隐式实例化pp=new ArrayTp; 2.显式实例化ep:template class ArrayTp;虽然没有创建或提及类对象 但还是会生成类声明(包含定义) 3.显式特例化ep:原类template class ArrayTp{ …}; 现... 阅读全文

posted @ 2007-03-07 07:06 Edward Xie 阅读(1442) 评论(0) 推荐(0)

类模板 使用多个类型参数
摘要:// pairs.cpp -- define and use a Pair template#include #include template class Pair{private: T1 a; T2 b;public: T1 & first(); T2 & second(); T1 first() const { return a; } T2 second(... 阅读全文

posted @ 2007-03-07 06:49 Edward Xie 阅读(673) 评论(0) 推荐(0)

指定小数位数输出
摘要:按有效位输出是 setprecision,按小数位数输出也是setprecision,但到底是谁取决于fixed。cout #include using namespace std; int main( void ){ const double value = 12.3456789; cout << value << endl; // 默认以6精度,所以输出为 12.3457 ... 阅读全文

posted @ 2007-03-07 06:45 Edward Xie 阅读(495) 评论(0) 推荐(0)

类模板 数组模板非类型参数 (与) 递归使用模板
摘要:////////////////////////////////////////////////////////////////arraytp.h////////////////////////////////////////////////////////////// //arraytp.h -- Array Template #ifndef ARRAYTP_H_#define ARRAYTP... 阅读全文

posted @ 2007-03-07 06:45 Edward Xie 阅读(313) 评论(0) 推荐(0)

类模板(实例为指针的例子)
摘要://///////////////////////////////////////////// stcktp1.h -- modified Stack template///////////////////////////////////////////#ifndef STCKTP1_H_#define STCKTP1_H_ template class Stack{private: enu... 阅读全文

posted @ 2007-03-06 19:43 Edward Xie 阅读(758) 评论(0) 推荐(0)

模板类 基础
摘要:export关键字可以让模板的 成员申明和定义分开两个文件但是要加 ep://头文件申明加export关键字,定义就可以放另外一个文件中按常用方法定义export template class Stack{ …}; ////////////////////////////////////////////////////////////////////////stacktp.h/////////... 阅读全文

posted @ 2007-03-05 10:59 Edward Xie 阅读(160) 评论(0) 推荐(0)

预处理指令
摘要:由ANSI的标准规定, 预处理指令主要包括: #define #error #if #else #elif #endif #ifdef #ifndef #undef #line #pragma 由上述指令可以看出, 每个预处理指令均带有符号"#"。下面只介绍一些常 用指... 阅读全文

posted @ 2007-03-05 10:25 Edward Xie 阅读(320) 评论(0) 推荐(0)

多重继承虚基类
摘要:// worker singer:public worker waiter:public worker singerwaiter:public singer,public waiter 如上如继承关系的时候 =>>问题出现:singerwaiter ... 阅读全文

posted @ 2007-03-05 04:58 Edward Xie 阅读(217) 评论(0) 推荐(0)

私有继承(has a)
摘要:1>访问基类方法 用作用域解析操作符:: ep:valarray::size();//*************************************************//2>访问基类对象(对象数据成员) 用强制转换ep:const string & Student::name() const{ return (const string &) *this;} //******... 阅读全文

posted @ 2007-03-04 10:24 Edward Xie 阅读(232) 评论(0) 推荐(0)

valarray模板类使用(has a包含)
摘要:///////////////////////////////////////////////////////////////////////////////////main.cpp/////////////////////////////////// use_stuc.cpp -- using a composite class// compile with studentc.cpp#inclu... 阅读全文

posted @ 2007-03-04 06:48 Edward Xie 阅读(429) 评论(0) 推荐(0)