2007年5月8日
一般來說vector不適合做經常刪除的容器,但是在某些情況下,我們確實需要刪除vector的部分元素,一般的方式類為v.erase(remove_if(v.begin(), v.end(), func)).但是本人懶的把操做寫到另一個函數中,下面是一個更好的辦法
vector<int>::reverse_iterator rit = v.rbegin();
while (rit != v.rbegin())
{
if (func(*rit)) //檢查是否需要刪除
v.erase((++rit).base());
else
++rit;
}
其中reverse_iterator和iterator的關系與轉換是關鍵,STL真是設計的強大.
2007年3月31日
使用VIM編寫程序,發現切換頭文件和代碼文件很麻煩,發現一個好東西A.vim,具體使用參數如下:
A switches to the header file corresponding to the current file being edited (or vise versa)
:AS splits and switches
:AV vertical splits and switches
:AT new tab and switches
:AN cycles through matches
:IH switches to file under cursor
:IHS splits and switches
:IHV vertical splits and switches
:IHT new tab and switches
:IHN cycles through matches
<Leader>ih switches to file under cursor
<Leader>is switches to the alternate file of file under cursor (e.g. on??<foo.h> switches to foo.cpp)
<Leader>ihn cycles through matches
下載地址如下:http://www.vim.org/scripts/script.php?script_id=31
下載后放到/usr/share/vim/vim61/plugin/就可以了,如果啟動時候有錯誤,就下載一個老一點的版本.
indent是一個常用的Linux的C代碼格式化工具,但是參數太多,很難記憶,目前發現一組參數,可以格式化為我常用的代碼格式.
-bad?-bap?-bbb?-bbo?-nbc?-bl?-bli0?-bls?-c33?-cd33?-ncdb?-ncdw?-nce?-cli0?-cp33?-cs?-d0?-nbfda??-nfc1?-nfca?-hnl?-ip5?-l75?-l
p?-pcs?-nprs?-saf?-sai?-saw?-nsc?-nsob?-nss?-i4?-ts4?-ut
保存在~/.indent.pro,就是默認的indent參數了.
2007年3月12日
從Google上發現了這個C++專門的Blog,發現很不錯,有自己寫的欲望了,申請了一下,今天開張,希望能記錄一些經驗,保存一些自己看到的比較好的文章.