原创 簡單Windows控制檯貪喫蛇(二維數組模擬地圖, 鏈表模擬貪喫蛇, WASD控制行走, gotoxy替換刷新操作)

#include <stdlib.h> #include <iostream> #include <list> #include <conio.h> #include <time.h> #include <algorithm> #incl

原创 C++ 類的多態(方法的重載與繼承)

直接上例子:   #include "stdafx.h" #include using namespace std;   class Base { public:  void f(int x){cout << "Base::f

原创 Linux C 多線程

最近優化了一個程序,使其從單線程處理變爲多線程處理 線程爲常駐線程 簡單寫了一個例子 編譯:gcc testthread.c -otest -lpthread  注意編譯的時候一定要加-lpthread #include <stdio.

原创 C/C++ 簡單拆分字符串使用函數包括strstr, strcspn, strrchr

strstr, strcspn, strrchr函數的簡單應用  待拆分字符串: http://www.xxx.com|http://www.yyy.com:88 拆分結果:     http://www.xxx.com:0     ht

原创 C 不定長參數使用例

#include "stdafx.h" #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> #include <math.h> #inc

原创 C 拆分字符串(strtok,strsep)

頭文件string.h strtok是標準C函數 strsep是strtok的升級版,但是不支持WINDOWS C 函數原型啥的我就不往上粘了,直接上例子 這是strtok的: #include <iostream> #include <

原创 C++ 多線程 CreateThread函數使用例

#include <stdlib.h> #include <iostream> #include <list> #include <conio.h> #include <time.h> #include <algorithm> #incl

原创 C 簡單選擇排序

簡單選擇排序 時間複雜度O(n²) #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> #include <math.h> #inclu

原创 C++ 輸入輸出運算符重載

類的輸入輸出運算符重載必須使用友元函數 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> #include <math.h> #inc

原创 漢諾塔-遞歸

個人理解遞歸函數的基本要求就是,函數中調用函數本身,滿足特定的條件後返回。 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> #inc

原创 C++ volatile類型修飾符(type specifier), 多線程

volatile是被設計用來修飾被不同線程訪問和修改的變量 volatile的作用是: 作爲指令關鍵字,確保本條指令不會因編譯器的優化而省略,且要求每次直接讀值. 一個定義爲volatile的變量是說這變量可能會被意想不到地改變,這樣,編

原创 C++ Lambda表達式(還是比較習慣叫匿名函數)

不太情願, 但不得不承認, 我是最近才知道Lambda這個詞(前幾天丟人丟大了), 這是作爲一個程序猿的失職, 雖然很早以前就聽說過"匿名函數", 這裏記下, 引以爲戒.Lambda表達式, 又稱匿名函數:[capture](parame

原创 宏函數

在編譯預處理時,對程序中所有出現的“宏名”,都用宏定義中的字符串去代換,這稱爲“宏代換”或“宏展開”。宏定義是由源程序中的宏定義命令完成的。宏代換是由預處理程序自動完成的。若字符串是表達式,我們稱之爲函數式宏定義(宏函數)。 函數式宏定義

原创 簡單Windows控制檯貪吃蛇(二維數組模擬地圖, 鏈表模擬貪吃蛇, WASD控制行走, gotoxy替換刷新操作)

#include <stdlib.h> #include <iostream> #include <list> #include <conio.h> #include <time.h> #include <algorithm> #incl