Time of Update: 2018-12-07
Abstract這是一個實務上常用的功能,可惜在C語言的string.h並沒有提供,本文實作出一個小function達到此功能。Introduction比如說一個字串為[10,20],希望從逗號','抓到']'中間的20,C語言的string.h並沒有提供適當的function可以實現,比較接近的是strchr(),我就模擬strchr()的interface,寫了一個strchrn()‧ 第一個參數為目標字串,第二個參數為原始字串,第三個參數為起始字元,如',',第四個參數為結束字元,如']'
Time of Update: 2018-12-07
Abstract這是一個實務上常用的功能,可惜在C語言的string.h並沒有提供,本文實作出一個小function達到此功能,並搭配pointer。 Introduction在(筆記) 如何在字串中從指定字元抓到指定字元? (C/C++) (C),其實已經可以包含99%的需求,唯一的缺憾是,string.h的函數大都回傳的char *,若要更靈活的搭配string.h原本的函數,勢必提供pointer版的function。 第三與第四個參數,都改用char *‧ strchrp.c /
Time of Update: 2018-12-07
Abstract通常公司為了保護其智慧財產權,會自己定義檔案格式,其header區會定義每個byte各代表某項資訊,所以常常需要直接對binary檔的某byte直接進行讀取。Introduction使用環境:Windows XP SP3 + Visual C++ 6.0 SP6將讀取wf.bin的0x13 byte處的值。Method 1:使用fsetpos()fsetpos.c / C 1 /* 2 (C) OOMusou 2011 http://oomusou.cnblogs.com 3
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
雙重檢測鎖(Double-Checked Locking)實現的Singleton模式在多線程應用中有相當的價值。在ACE的實現中就大量使用ACE_Singleton模板類將普通類轉換成具有Singleton行為的類。這種方式很好地消除了一些重複代碼臭味,而且,最佳化後的效能較標準互斥版本提高15倍[1]。最近在用C++/CLI做一些工作,Singleton不可避免地需要用到,於是我又製造了一次車輪
Time of Update: 2018-12-07
Abstract若想將container中的iterator,從一個值取代成另外一個值,但container並沒有提供replace()這個member function,而是提供了replace()這個Generic
Time of Update: 2018-12-07
Abstract設定暫存器值是寫firmware時最常見的控制,本文歸納出C語言在寫firmware時常見的編程技巧,並與Verilog相互對照。Introduction本文將討論以下主題:1.將某bit強制設為12.將某bit強制設為03.將某bit做toggle (0變1,1變0)4.判斷某bit是否為15.判斷某bit是否為01.將某bit強制設為1C語言flag |= mask;或flag |= (1 << n);Verilogflag[n] =
Time of Update: 2018-12-07
Abstract由於C#的乾淨俐落與Visual Studio工具的增強,越來越多人選擇用C#開發GUI而捨棄MFC,但以前已經有太多程式使用Visual C++ 6.0與MFC開發,一時之間又不可能將C/C++的code全部用C#改寫,所以將原本用C/C++寫的Business Rule整理成DLL給C#使用也是個不錯的選擇。Introduction使用環境:Visual Studio 2008Step 1:使用Visual Studio
Time of Update: 2018-12-07
/***********write by myself***********//***********begin test file***********/#include <iostream>#include <string>int main(){ std::string str1 = " hello world! "; std::string trimstring = " "; std::cout << "str = \"" <<
Time of Update: 2018-12-07
Abstract通常公司為了保護其智慧財產權,會自己定義檔案格式,其header區會定義每個byte各代表某項資訊,所以常常需要直接對binary檔的某byte直接進行寫入,且連續寫入幾個byte表示某一數值資訊。Introduction使用環境:Windows XP SP3 + Visual C++ 6.0 SP6將寫入wf.bin的0x33 byte處的連續4 byte值。 1 /* 2 (C) OOMusou 2011 http://oomusou.cnblogs.com 3 4
Time of Update: 2018-12-07
Abstract一個很常見的需求:『將struct塞進vector』,在C++該怎麼做呢?Introduction使用環境:Visual C++ 9.0 / Visual Studio 2008由於vector只允許一個欄位,所以才會想將struct塞進vector,以彌補vector的不足。struct_in_vector.cpp / C++Code highlighting produced by Actipro CodeHighlighter
Time of Update: 2018-12-07
1.
Time of Update: 2018-12-07
Abstract若需要將程式碼放進word交報告或做檔案時,或許我們會想將程式碼加上行號方便講解,如同部落格園顯示程式碼那樣,我們該如何做呢?Introduction使用環境:Visual C++ 9.0 / Visual Studio 2008一段C++的小程式,可以幫程式碼加上行號後輸出。map_code_line.cpp / C++1 /* 2 (C) OOMusou 2008 http://oomusou.cnblogs.com3 4 Filename :
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
若要將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