原创 函數指針的筆記

參見<<c++ primer>> p237頁 bool (*pf)(const string &, const string &); typedef bool (*cmpFcn) (const string &,const string

原创 指向const對象指針&const指針

參見<<c++ primer>> 110頁 <<數組和指針>> 一節 =-=-=-=-=-=-=-=-=-=-=-=-=-指向const對象指針關鍵理解=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--= c

原创 sizeof的一點總結

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--= char str[] = "hello"; sizeof(str) = 6; void *p = ma

原创 不使用庫函數將字符串轉化爲數字 實現

int str2int(const char *str) { int temp = 0; const char *pstr = str;//ptr保存 if (*str=='-'||*str=='+') { str++; }

原创 <<c++ primer>> 函數指針的筆記

參見<<c++ primer>> p237頁 bool (*pf)(const string &, const string &); typedef bool (*cmpFcn) (const string &,const string

原创 String各類運算符重載的編寫示例

class myString { public: myString& operator=(char* s); myString& operator=(const myString& s); char& operator[](in

原创 編程實現任意長度的兩個正整數相加 代碼實現

char* addBigInt(char* num1,char* num2) { int c = 0;//進位,開始最低進位爲0 int i = strlen(num1)-1; int j = strlen(num2)-1; i

原创 數字與字符串互換

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-字符串轉化爲數字=-=-=-=--==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

原创 不使用庫函數將整數轉化爲字符串

void int2str(int n,char *str) { char buf[10] = ""; int i = 0; int len = 0; int temp = n < 0?-n:n; if (str==NULL)

原创 引用使用需要注意的總結

=-=-=-=-=-=-=-=-=-=-=-=千萬不要返回局部對象的引用-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--= const string &manip(const string& s) {

原创 從字符串的指定位置開始,刪除指定長度字符

//領會指針和其它內存操作的技巧 char *deleteChars(char *str,int pos,int len) { char *p = str + pos -1;//指向pos位置字符 int tt = strlen(s

原创 字符長度

以下是在centos_x32和centos_x64下對應的類型長度: /*******size of types on centos_x32*****************/ size of char:1 size of int:4

原创 設計一個公共的class,通過它的接口可以對任何類型的數組排序

template<class T> class Test { public: static void Sort(T *array,int len,bool (*Compare)(T& a,T& b))//static 可以直接通

原创 模板特化

模板的特化: 對某些類型進行特殊處理,下面是函數模板特化的一個例子: template<class T> bool IsEqual(T t1,T t2) { return t1==t2; } template<> bool IsE

原创 <<c++ primer>> 強制類型轉換

參見<<c++ primer>> p160頁 顯示強制類型很危險(問題源於類型已經改變時編譯器沒有提供任何警告或錯誤提示),儘量少用 =-=-=-=-=-=-=-=-=-=-=-=-=dynamic_cast-=-=-=-=-=-=-