ref : http://stackoverflow.com/questions/2693776/removing-trailing-newline-character-from-fgets-input
目前分類:C / Cpp (75)
- Nov 15 Thu 2012 22:55
C_Cpp : 去除字串的'\n'
- Nov 11 Sun 2012 15:20
C/C++ - pass parameter to callback function
ref : http://stackoverflow.com/questions/4644409/passing-parameters-for-callback-function
- Nov 02 Fri 2012 17:51
C/Cpp : 在顯示的數字前面補0
- Nov 01 Thu 2012 16:23
C - popen()
- Nov 01 Thu 2012 11:48
C/Cpp : memset()
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個'-' .
- Aug 02 Thu 2012 22:37
C - static
- Aug 02 Thu 2012 22:05
C - Volative
- Aug 02 Thu 2012 20:35
c/c++ - sizeof()
- Apr 07 Sat 2012 21:11
Cpp - When should I use a "private" constructor?
一般來說 , 宣告在private區域就是代表部給class以外的人使用 ,
所以若把constructor宣告在private區域 , 代表就是不可以對這個class instantize.
- Apr 07 Sat 2012 14:47
Cpp - iterator
- Apr 05 Thu 2012 19:29
Cpp - reference counting
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
- Apr 03 Tue 2012 21:23
Cpp - map & comparator
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;
- Apr 03 Tue 2012 21:17
Cpp - Function Object
- Apr 03 Tue 2012 21:05
Cpp - STL algorithm
In addition to container classes and iterators,
STL also provides a number of generic algorithms for working with the elements of the container classes.
- Mar 31 Sat 2012 21:01
Cpp - istringstream
- Mar 31 Sat 2012 20:38
Cpp - feof and fgets. (never use feof as the exit indicator for a loop)
我們在讀檔時 , 因為不知道檔案的大小 , 通常需要一個方法來幫我們判斷是否已經讀到檔案結尾.
but ... You should never use feof() as the exit indicator for a loop.
- Mar 24 Sat 2012 23:23
Cpp - dynamic_cast<>
在C++中 , 若有兩個derived class 繼承同一個abstract base class時 ,
我們若以base class pointer (or reference )來接derived class的instance , 並使用base class的pointer
- Mar 24 Sat 2012 20:14
Cpp - member function , Virtual function & Pure Virtual function
- Mar 16 Fri 2012 15:34
Cpp - Multiple inheritance
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 ,
- Mar 16 Fri 2012 11:53
Cpp - member function
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 –>).