目前分類:C / Cpp (75)

瀏覽方式: 標題列表 簡短摘要

ref : http://stackoverflow.com/questions/2693776/removing-trailing-newline-character-from-fgets-input


文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣()

ref : http://stackoverflow.com/questions/4644409/passing-parameters-for-callback-function


JerryCheng 發表在 痞客邦 留言(0) 人氣()

在C中 , 我們可以用sprintf()來建立一個string的format , 

而有時我們會需要用到一些時間格式的format , 像2012-01-01 , 

文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在linux的C library中 , 提供了popen() function可以讓我們建立相同於pipeline的功能 ,

popen()的format如下:

文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣()

memset ( void * ptr, int value, size_t num ) , 可以讓我們對pointer所指向的一個記憶體空間塞入資料 , 
在memset中主要有三個參數 , 分別是:
  ptr : Pointer to the block of memory to fill.
  value : Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.
  num : Number of bytes to be set to the value.
  for example : 
#include <stdio.h> 
#include <string.h> 
int main () 
{ 
char str[] = "almost every programmer should know memset!"; 
memset (str,'-',6); 
puts (str);
return 0; 
}
 我們可以看到memset幫我們在str所指向的記憶體空間中塞入了6個'-' .
 

 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在C中 , static是一個Storage-class specifiers,

它的主要作用有兩個,一個是作用域的限制,一個是指定存儲方式。

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Compiler 在編譯程式時常常會對代碼進行優化的動作 , 

所謂優化的動作指的就是....舉個例子:

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在c中 , sizeof() function可以回傳該變數的位元組數目

for example:

JerryCheng 發表在 痞客邦 留言(0) 人氣()

一般來說 , 宣告在private區域就是代表部給class以外的人使用 , 

所以若把constructor宣告在private區域 , 代表就是不可以對這個class instantize.

JerryCheng 發表在 痞客邦 留言(0) 人氣()

In C++, an iterator is any object that, pointing to some element in a range of elements (such as an array or a container),

 has the ability to iterate through the elements of that range using a set of operators

JerryCheng 發表在 痞客邦 留言(0) 人氣()

The reference count tracks how many references to the object are currently active. 
When the number of references drops to zero, the object deletes itself. 
The last part is worth repeating: The object deletes itself; the program never explicitly deletes the object.
 

Here are the rules for reference counting:

 0. When the object is first created, its reference count is 1. At this point, the program has a single pointer to the object.
   1. Attach a counter to each pair in memory.
   2. When a new pointer is connected to that pair, increment the counter.
   3. When a pointer is removed, decrement the counter.
   4. Any cell with 0 counter is garbage. 
 

 ref : http://msdn.microsoft.com/en-us/library/ff485846(v=vs.85).aspx

JerryCheng 發表在 痞客邦 留言(0) 人氣()

In their implementation in the C++ Standard Template Library, map containers take four template parameters:

template < class Key, class T, class Compare = less<Key>,class Allocator = allocator<pair<const Key,T> > > class map;

JerryCheng 發表在 痞客邦 留言(0) 人氣()

consider the following function:

int foo();

JerryCheng 發表在 痞客邦 留言(0) 人氣()

In addition to container classes and iterators, 

STL also provides a number of generic algorithms for working with the elements of the container classes. 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

因為istringstream是繼承自ifstream , 

所以我們可以利用ifstream的一些特性 , 輕鬆的在讀取data時 , 轉換到我們所需的type.

JerryCheng 發表在 痞客邦 留言(0) 人氣()

我們在讀檔時 , 因為不知道檔案的大小 , 通常需要一個方法來幫我們判斷是否已經讀到檔案結尾.

but ... You should never use feof() as the exit indicator for a loop. 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

在C++中  , 若有兩個derived class 繼承同一個abstract base class時 , 

我們若以base class pointer (or reference )來接derived class的instance , 並使用base class的pointer

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Pure Virtual function , 

Pure Virtual function代表base class並無implement這個function的內容 , 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Multiple inheritance enables a derived class to inherit members from more than one parent.

While multiple inheritance seems like a simple extension of single inheritance , 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Classes can contain data and functions. These functions are referred to as "member functions."

Any nonstatic function declared inside a class declaration is considered a member function and is called using the member-selection operators (. and –>)

JerryCheng 發表在 痞客邦 留言(0) 人氣()

1 234