條款1:盡量用const和inline而不用#define

原文連結盡量用const和inline而不用#define也稱為:盡量用編譯器而不用預先處理。原因:(1)#define ASPECT_RATIO 1.653 編譯前預先處理程式會將ASPECT_RATIO 替換為1.653,編譯出錯時只會指出1.653,而無法跟蹤ASPECT_RATIO,不便於調試(2)#define max(a,b) ((a) > (b) ? (a) : (b))有可能出錯:int a = 5, b = 0;max(++a, b);// a 的值增加了2次max(++

stl string 使用

stl string 使用1. 尋找字元std::wstring  strData = L"<result>[北京市, 上海市, 深圳市]</result>"void DoF(const std::wstring &strData, std::list<std::wstring>& listDo){    std::wstring strTarB = L"<result>[";    std::wstring strTarE =

class中預設的4個函數的實現

原文連結class類中預設會實現4個函數,分別為預設建構函式,拷貝建構函式,解構函式和=運算子多載 #include <iostream>using namespace std;class myString{ public: myString(const char *str=NULL); myString(const myString &other); ~myString(); myString &

emacs配置大全(cedet+ecb+cscope+gdb-ui)-jzj

原文地址:http://blog.csdn.net/nhczp/article/details/1862695本文主要討論以下幾方面的設定:1.字型2.cedet3.ecb4.cscope5.gdb-many-window6.行號7.縮排 環境:openSUSE 10.2預設裝的是Emacs 21,我從網上下了Emacs 22.1的tar包,編譯安裝。1.字型    預設的字型非常之小,以下是一篇非常詳細的Emacs下設定字型的教程http://www.yuanma.org/data/2006/

boost::array與std::vector使用與效能

大家都希望可以像操作STL容器一樣的去運算元組,C++可沒有提供這個東西,有時候你會選擇使用vector來替代,不過這畢竟不是個好的辦法,畢竟vector類比動態數組比較穩妥,而用它去替代一個普通的數組,開銷畢竟太大了。而恰好,boost::array就為你提供了這個功能。boost::array的定義如下(簡化):詳情參見相關檔案Code highlighting produced by Actipro CodeHighlighter

用emacs 建立開發環境,安裝ecb和cedet的全過程

原文地址:http://blog.csdn.net/hide1713/article/details/1647209更多圖片請看http://ecb.sourceforge.net/先下載這兩個軟體的安裝包ecb      http://ecb.sourceforge.net/cedet   http://cedet.sourceforge.net/然後tar zxvf ecb-2.32.tar.gzcd cedet-1.0pre4make    (ecb需要設定Makefile

glib 雙向鏈表

原文地址:http://hi.baidu.com/study_together/blog/item/f14cb83319f70d94a8018e3e.html編譯:編譯:gcc -g -Wall -O0 fuck.c -o fuck `pkg-config --libs --cflags glib-2.0`1基本操作這裡是使用 GList 可以進行的一些常見操作:#include <glib.h>#include <stdio.h>int main(int argc,

多線程執行個體 同步鎖

多線程執行個體 :lp.c#include <pthread.h>#include <stdio.h>#include <sys/time.h>#include <string.h>#define MAX 10pthread_t thread[2];pthread_mutex_t mut;int number=0, i;void *thread1(){ printf ("thread1 : I'm thread 1\n");for (i =

對委託的簡單理解

原文連結:http://blog.csdn.net/wxw45601/article/details/7668499參考連結:http://wenku.baidu.com/view/970280c45fbfc77da269b1f5.html在編程過程中,我們習慣把資料作為參數傳遞給方法(例:int

【轉載】boost::lexical_cast 的使用

1,字串 到 數實值型別的轉換 2,數值 到 字串的轉換 3,異常處理情況 4,boost::lexical_cast 的原型: template<typename Target, typename Source>     Target lexical_cast(Source arg); lexical_cast 是依賴於字串流 std::stringstream 的,其原理也是相當的簡單:把源類型 (Source) 讀入到字元流中,再寫到目標類型 (Target)

多線程 helloworld

多線程執行個體2:#include <stdio.h> #include <stdio.h>#include <pthread.h>void thread(void) {

利用boost::asio實現一個簡單的伺服器架構

boost, asio, SPServer  boost::asio是一個高效能的網路開發庫,Windows下使用IOCP,Linux下使用epoll。與ACE不同的是,它並沒有提供一個網路架構,而是採取組件的方式來提供應用介面。但是對於常見的情況,採用一個好用的架構還是能夠簡化開發過程,特別是asio的各個非同步介面的用法都相當類似。  受到 SP Server 架構的影響,我使用asio大致實現了一個多線程的半非同步半同步伺服器架構,以下是利用它來實現一個Echo伺服器:1. 實現回調:

boost::asio一個簡單的echo伺服器

以前使用ACE實現Server架構,但是覺得太笨重,決定採用boost.asio來寫伺服器程式: 1.伺服器構建在linux上面;當然也可以在windows下運行 2.io部分採用非阻塞模式、商務邏輯部分採用同步線程池實現 3.封裝io操作及狀態,使用者應用程式無需關心io詳細操作所以決定採用boost::asio架構來寫伺服器:boost::asio::io_service提供了核心IO功能、和非同步IO對象,它包括: boost::asio::ip::tcp::socket

Googlemaps範圍搜尋

http://code.google.com/p/goog-maps-demo/source/browse/trunk/examples/Map/fitBounds.html?r=6http://www.tongmap.cn/code/webgis3.0--API/symbols/sic.LatLngBounds.html1 var geocoder = new google.maps.Geocoder(); //地圖搜尋對象geocoder.geocode( { 'address':

google maker 標註

參考地址:http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/examples/marker-simple.html<!DOCTYPE html><html><head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta

js 正則匹配(去掉html標籤)

原文地址:http://cgxcn.blog.163.com/blog/static/1323124220095384043365/js 正則匹配(去掉html標籤)1,得到網頁上的連結地址:string matchString =

Boost學習之格式化輸出–format

文章目錄 所需標頭檔:範例程式碼: boost::format類提供了類似C語言裡'printf'功能的格式化輸出能力,當然功能更強大。所需標頭檔:#include <boost/format.hpp>範例程式碼:#include <iostream> #include <string> #include <boost/format.hpp>   using namespace std;

google 根據地址得ip 並顯示

參考地址:http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/examples/index.html<!DOCTYPE html><html><head><meta name="viewport" content="initial-scale=1.0, user-scalable=no"/><meta http-equiv="content-type"

Boost智能指標——shared_ptr

boost::scoped_ptr雖然簡單易用,但它不能共用所有權的特性卻大大限制了其使用範圍,而boost::shared_ptr可以解決這一局限。顧名思義,boost::shared_ptr是可以共用所有權的智能指標,首先讓我們通過一個例子看看它的基本用法: #include <string>#include <iostream>#include <boost/shared_ptr.hpp>class implementation{public:    ~

boost 庫 enable_shared_from_this 實現原理分析

使用情景:當類對象被 shared_ptr 管理時,需要在類自己定義的函數裡把當前類對象作為參數傳給其他函數時,這時需要傳遞一個 shared_ptr ,否則就不能保持 shared_ptr 管理這個類對象的語義(因為有一個 raw pointer 指向這個類對象,而 shared_ptr 對類對象的這個引用沒有計數,很有可能 shared_ptr 已經把類對象資源釋放了,而那個調用函數還在使用類對象——顯然,這肯定會產生錯誤)。很好奇這個模板類的實現。先看看怎麼使用:對一個類 A

總頁數: 61357 1 .... 3750 3751 3752 3753 3754 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.