Time of Update: 2018-12-05
NetClient.h#ifndef NETCLIENT_H_#define NETCLIENT_H_#include <stdio.h>#include <string.h>#include <errno.h>#include <sys/socket.h>#include <resolv.h>#include <stdlib.h>#include <netinet/in.h>#include <arpa/
Time of Update: 2018-12-05
#include <stdio.h> #include <iostream>#include <stdlib.h>#include <conio.h> using namespace std;void Test(char h){cout<<"press key===="<<h<<endl;switch(h){case 'a':case
Time of Update: 2018-12-05
發現最近寫的程式總是要用到檔案操作,所以把C語言與檔案輸入輸出有關的函數複習一下。 C語言是通過將一個檔案類型指標與檔案關聯起來來對檔案進行開啟、關閉、輸入、輸出。檔案類型為FILE(實際上是一個結構體)。定義一個檔案指標為FILE *fp;就可以將fp和某個檔案關聯起來進行操作了。例如要開啟一個檔案: FILE *fp;
Time of Update: 2018-12-05
//N階螺旋矩陣#include <stdio.h>#include <stdlib.h>int main(){ int N,i,j,n,num=1; int a[10][10]={0}; printf("輸入你要輸出的幾階中斷:"); scanf("%d",&N); for(n=0;n<=N/2;n++) { for(j=n;j<=N-n-1;j++)
Time of Update: 2018-12-05
/*linux tirminal 中輸入vim demo_thread.c, 然後輸入以下代碼:*/#include <pthread.h>#include <stdio.h>#include <sys/time.h>#include <string.h>#define MAX 10//定義兩個線程數組pthread_t thread[2]; //線程值,用於線程鎖pthread_mutex_t mut;//便於觀察線程非同步與同步操作int
Time of Update: 2018-12-05
小dome#include <windows.h> #include <stdio.h>int main(){int n=7; number2:printf("hello world\n"); if (n==7){ n=8;printf("n=7 start\n");goto number0;printf("n=7 end\n");}else{printf("n=8 start\n");goto number1;printf("n=8 end\n");}
Time of Update: 2018-12-05
一. 分割//字串分割函數std::vector<std::string> CStringTooler::split(std::string str,std::string pattern){ std::string::size_type pos; std::vector<std::string> result; str+=pattern;//擴充字元串以方便操作 int size=str.size(); for(int i=0; i<
Time of Update: 2018-12-05
1. free(): invalid next size (fast): 0xb73004e8 *** 這一般是屬於記憶體使用量錯誤造成的。有可能是malloc 或者new 記憶體時的長度,和真正使用指標指向長度時越辦造成的。 如 char *str = malloc(5); memcpy(str, "helloworld", 11); // free(str) 時便出錯以上的錯誤2.linux select 與windows
Time of Update: 2018-12-05
static_cast:靜態類型轉換。用於基礎資料型別 (Elementary Data Type)之間的轉換。 用法:static_cast <typeid> (expression)。
Time of Update: 2018-12-05
sizeof 是一個操作符(operator),其作用返回一個對象或資料類型所佔的記憶體位元組數。strlen(char*)函數求的是字串的實際長度,它求得方法是從開始到遇到第一個'\0',如果你只定義沒有給它賦初值,這個結果是不定的,它會從aa首地址一直找下去,直到遇到'\0'停止。strlen返回的是有效字串長度,不包含結束符‘\0’。函數strcpy則連‘\0’一起複製。 基本類型sizeof執行個體#include "stdafx.h"#include <stdlib.h>#
Time of Update: 2018-12-05
文章目錄 動態申請記憶體操作符 new釋放記憶體操作符delete保持平衡
Time of Update: 2018-12-05
#include <windows.h> //#define NDEBUG#include <assert.h>int main(){int n=9;assert(n!=9);//assert()括弧中的運算式if true則不會出現端斷言錯誤,assertion failed system("pause");return 0;}void assert( int expression );assert的作用是現計算運算式 expression ,如果其值為假(即為0),
Time of Update: 2018-12-05
#include <time.h>#include <stdio.h>void DataBase::WriteInfo(int num){time_t timer;char bufferTime[20];time(&timer);strftime(bufferTime,20,"%Y-%m-%d %H:%M:%S",localtime(&timer));//FILE* fid=fopen("/opt/HaiBao/Info.log","a+");FILE*
Time of Update: 2018-12-05
//基類:#include <iostream.h>class Animal(){public: Animal(int height,int weight) { cout<<"Animal"<<endl; } void eat() { cout<<"animal eat"<<endl; }};//子類:class fish:public
Time of Update: 2018-12-05
volatile概念volatile 是易變的、不穩定的意思。 volatile關鍵字和const 一樣是一種類型修飾符,用它修飾的變數表示可以被某些編譯器未知的因素更改,比如作業系統、硬體或者其它線程等。遇到這個關鍵字聲明的變數,編譯器對訪問該變數的代碼就不再進行最佳化,從而可以提供對特殊地址的穩定訪問。先看看下面的例子: int i=10; int j = i;//(1)語句 int k = i;//(2)語句這時候編譯器對代碼進行最佳化,因為在(1)、(2)兩條語句中,i
Time of Update: 2018-12-05
通常對於普通函數來說,要訪問類的保護成員是不可能的,如果想這麼做那麼必須把類的成員都生命成為public(共用的),然而這做帶來的問題遍是任何外部函數都可以毫無約束的訪問它操作它,c++利用friend修飾符,可以讓一些你設定的函數能夠對這些保護資料進行操作,避免把類成員全部設定成public,最大限度的保護資料成員的安全。友元能夠使得普通函數直接存取類的保護資料,避免了類成員函數的頻繁調用,可以節約處理器開銷,提高程式的效率,但矛盾的是,即使是最大限度的保護,同樣也破壞了類的封裝特性,這即是友
Time of Update: 2018-12-05
文章目錄 3.宏定義運算4.sizeof(union)5.數組記憶體配置6.char <==> int 1.無符號int自動轉換void foo(){unsigned int a = 6; int b = -20; (a+b > 6)?puts("> 6") : puts("<= 6"); //輸出 >6/*這個問題測試你是否懂得 C
Time of Update: 2018-12-05
在C++中,庫的地位是非常高的。基礎庫boost“准”標準庫boost庫是經過千錘百鍊,可移植提供原始碼的C++庫,作為標準庫的後備。跨平台的。有一個大的C++社區支援Boost中比較著名的庫有RegexRegex庫Thread可移植的C++多線程庫Pool記憶體池管理Graph圖組件和演算法STLportSGI STL庫的跨平台可移植版本GUI庫MFC大名鼎鼎的微軟基礎類庫(Microsoft Foundation Class)。大凡學過VC++的人都知道這個庫。雖然,從技術角度講,MFC是不
Time of Update: 2018-12-05
關鍵詞static,const修飾成員變數,成員函數,輸入參,傳回值,volatile,記憶體管理new、delete、malloc、free;delete-delete[]的區別;記憶體配置(堆區,棧區,靜態區,常量區),記憶體泄露,函數返回指標問題,資料類型class-struct區別;指標-引用的區別;sizeof,strlen(),字串編程字串倒序;http://www.cnitblog.com/qlb5626267/archive/2008/11/23/51819.html物件導向多態
Time of Update: 2018-12-05
函數指標-指標函數函數指標的重點是指標。表示的是一個指標,它指向的是一個函數。eg: int (*pf)();指標函數的重點是函數。表示的是一個函數,它的傳回值是指標。eg: int* fun();數組指標-指標數組數組指標的重點是指標。表示的是一個指標,它指向的是一個數組。eg: int (*pa)[8];指標數組的重點是數組。表示的是一個數組,它包含的元素是指標。eg: int* ap[8];類模板-模板類類模板的重點是模板。表示的是一個模板,專門用於產生類。eg: template<