Time of Update: 2018-12-07
Abstract在(原創) 如何將字串前後的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++) (STL) 中已經可順利將字串前後的空白去除,且程式相當的精簡,在此用另外一種方式達到此要求,且可同時將whitespace去除,並且使用template寫法。Introduction原來版本的程式在VC8可執行,但無法在Dev-C++執行,目前已經修正。stringTrim1.cpp / C++1 /* 2 (C)
Time of Update: 2018-12-07
Abstract若用C語言配合迴圈,這是個很簡單的題目,但若用C++配合STL,則有很漂亮的寫法。Introduction陣列中有2、3、1、3、5五個值,希望能列出大於2的所有元素。C++1 /* 2 (C) OOMusou 2008 http://oomusou.cnblogs.com3 4 Filename : GenericAlgo_remove_copy_if_predicate.cpp5 Compiler : Visual C++ 8.06 Description :
Time of Update: 2018-12-07
Abstract若想將container中的iterator,從一個值取代成另外一個值,但container並沒有提供replace()這個member function,而是提供了replace()這個Generic
Time of Update: 2018-12-07
1.
Time of Update: 2018-12-07
Abstract前一篇(原創) 如何使用C語言的標準函式庫進行排序? (C)談到使用C語言stdlib.h的qsort()對array進行排序,C++呢?STL也提供了sort() algorithm。IntroductionSTL的sort()不僅僅支援array,還支援其餘的container如vector,list等,這也是泛型之美,container和algorithm徹底decouple,讓algorithm可以支援各種container,達到最大的reuse,由於STL是C++ 98
Time of Update: 2018-12-07
一、什麼是對齊,以及為什麼要對齊:1.
Time of Update: 2018-12-07
Abstractfor_each()是STL中少數可以回傳值的algorithm,此範例在展示for_each()此特殊功能與function object可以留住state的特性。Introductionfunction object與global function的差別除了function object可以傳入參數外,還可以不使用static就可以留住state。一個簡單的需求,想要每印n個數字就換行,並且統計出所有iterator的和,所以function
Time of Update: 2018-12-07
很多STL algorithm都是_if結尾的,讓我們可以帶function進去,若配合function object,可讓function更有彈性!!以下的範例想利用count_if()
Time of Update: 2018-12-07
IronPython 1.0 Release CandidateOne of the great features of the .NET framework is the Common Language Infrastructure (CLI). The CLI provides a common foundation for a wide variety of programming languages. IronPython is a project that implements
Time of Update: 2018-12-07
copy() algorithm是很好用的algorithm,但偏偏就是沒有copy_if(),但透過remove_copy_if()則可達到相同的要求。remove_copy_if()的思考方式和copy_if()相反,若UnaryPredicate為true,則不copy,若為false,則copy。此範例demo若為remove_copy_if()
Time of Update: 2018-12-07
若要將vector中反過來列印,該怎麼做呢?STL提供了reverse_iterator。 1/**//* 2(C) OOMusou 2006 http://oomusou.cnblogs.com 3 4Filename : ReverseIterator.cpp 5Compiler : Visual C++ 8.0 / ISO C++ 6Description : Demo how to use reverse_iterator 7Release : 12/17/2006
Time of Update: 2018-12-07
推薦閱讀:C++反組譯碼程式碼分析–函數調用C++反組譯碼程式碼分析–迴圈結構C++反組譯碼程式碼分析–偷調函數走進記憶體,走進彙編指令來看C/C++指標 代碼如下: #include "stdlib.h" int sum(int a,int b,int m,int n) { return a+b; } void main() { int result =
Time of Update: 2018-12-07
Abstract STL並沒有提供這樣的algorithm,透過簡單的方法,就可以達成這個需求。Sample
Time of Update: 2018-12-07
map和multimap都自帶find(),不需Generic
Time of Update: 2018-12-07
此範例demo如何使用STL的queue container,要將資料加進queue時,只要用q.push(item)即可,但要取出資料時,並不是用q.pop(),而是用q.front()取出最前面的資料,q.pop()則是將最前面的資料取出queue,其回傳值為void。 1/**//* 2(C) OOMusou 2006 http://oomusou.cnblogs.com 3 4Filename : Queue.cpp 5Compiler : Visual C++ 8.0 6
Time of Update: 2018-12-07
大家都體會過sequential container搭配copy() algorithm,只要一行程式就可以將所有值輸出到cout,map這種associative container就無法用這一招,是否有其它方式解決呢?map這種associative container因為是雙值,若用copy()到cout,會讓cout傻眼,不知道要抓拿一個值,當然用for loop一定可以,但基於使用STL的最高境界:不用for/while loop,此範例我們使用了for_each()
Time of Update: 2018-12-07
原文地址:http://hi.baidu.com/chzhao007/blog/item/e9dbc5ac1191bc034b36d6df.html前幾天,我竟被只小鳥小覷了一下,我承認本人blog中張貼出來的代碼確實一般,所以我得在此在重審一下:本人張貼出來的代碼都不是本人最終代碼!本人blog中到現在確實用C寫的代碼很多,但不代表本人不崇尚C++的對象編程,只不過本人現在從事的許多方面用C和彙編搞起來比較方便,所以用C寫東東比起C++來隨手。為了使本人blog闡述的東東近於完善,在此就寫下本
Time of Update: 2018-12-07
原文地址:http://hi.baidu.com/tangguoshequ/blog/item/d587dc170878c8946538dbd1.html1. Levenshtein Distance該演算法又稱之為 "編輯距離",用於計算兩個字串的相似程度。原理很簡單,就是返回將第一個字串轉換(刪除、插入、替換)成第二個字串的編輯次數。次數越少,意味著字串相似性越高。演算法原理:Wikipedia - Levenshtein
Time of Update: 2018-12-07
原文連結:http://www.cppblog.com/jialisoft/archive/2012/09/26/192071.html首先展示一個最簡單的單例模式例子,代碼如下: class NetworkService { public: // 對外提供的唯一方法函數,用於擷取唯一的對象指標 static NetworkService* GetInstance() { if(m_pInstance == NULL) {
Time of Update: 2018-12-07
原文連結:http://www.cppblog.com/newcnzz/archive/2012/09/29/192428.htmlC++提供了四個轉換運算子:const_cast <new_type> (expression)static_cast <new_type> (expression)reinterpret_cast <new_type> (expression)dynamic_cast <new_type> (expression)