原创 c++ std::getline

聲明 C++ 98 中的聲明格式 (1) istream& getline (istream& is, string& str, char delim); (2) istream& getline (istream& is

原创 Linux網絡編程echo簡單示例2--select實現

//select_echo_server.c #include <stdio.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <unistd.h

原创 c/c++預處理

C語言與C++中中編譯預處理的學習記錄: 首先三種形式的命令:宏定義,文件包含,條件編譯命令。 1、宏定義主要是:#define,#undef 如下: #define PI 3.1415926                    /*不

原创 Linux網絡編程echo簡單示例1

    今天看<<unix網絡編程>>,看了書上簡單的tcp/ip的簡單示例,決定還是寫一寫. 服務端   //simple_echo_server.c #include <stdio.h> #include <errno.h> #in

原创 字節對齊算法

字節對齊是在分配內存時需要考慮的問題. 正常人類算法: unsigned int calc_align(unsigned int n,unsigned align) { if ( n / align * align == n)

原创 __GUNC__宏定義

__GUNC__宏定義 __GNUC__  __GNUC_MINOR__ __GNUC_PATCHLEVEL__是gcc中的預定義宏 分別代表gcc

原创 宏定義中使用do{}while(0)的好處

#define MACRO_NAME(para) do{macro content}while(0)   的格式,總結了以下幾個原因:   1,空的宏定義避免warning: #define foo() do{}while(0) 2,

原创 linux free詳解

      一直以來對linux的內存的查看都是一知半解, 今天有時間詳細瞭解了下free的命令 ,在這塊整理記錄下。       free命令可以在linux下查看系統的內存的使用情況。       主要參數有:       -b   

原创 技巧:在 C/C++中如何構造通用的對象鏈表

說明 本文轉自 : http://www.ibm.com/developerworks/cn/linux/l-tip-prompt/tip02/index.html  點擊原文地址 虛擬鏈表和類鏈表可以很好地實現這一點 您是否做過這樣

原创 c/c++可變宏定義

c99支持了可變參數的宏. 使用宏的時候,參數如果不寫,宏裏用 #,## 這樣的東西會擴展成空串。example: #include<stdio.h

原创 c++11 decltype

c++11 decltype 在c++11中decltype跟auto都可以作爲類型指示符用來進行類型推導(編譯期)。 語法: decltype ( e ) 推導規則: 1. 如果參數是一個沒有帶括號的標

原创 一個簡單的linux的測試修改模板

//一個簡單的linux的測試用例模板 //編譯命令 : g++ -o1 -g simple_test_template.cpp -lpthread -o simple_test.exe //標準c頭文件 #include <stdi

原创 c/c++函數 -strtol strtoll strtoul strtoull 使用注意項cc

說明 在項目開發時,字符串跟整形的轉換是普遍需求的一個功能,在c/c++中常用的幾個函數包括 strtol strtoll strtoul strtoull。 目前我們的項目裏面進行轉換的時候都是直接調用,對被轉換的字符串是否有效,轉換

原创 gettimeofday

函數原型 #include <sys/time.h> int gettimeofday(struct timeval *tv, struct timezone *tz); int settimeo

原创 c++primer筆記之數組與指針的一些總結

數組的定義方式: 類型 數組名[維度]; eg: int a[10] , int b[10][10][10];  //注意:   1.數組的維度也是數組類型的一部分。     eg: int a[10];  數組a的類型爲int[10];