C/C++/Linux/Embedded

学习也是一种乐趣
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

  • 随笔 - 4
  • 文章 - 4
  • 评论 - 4
  • 引用 - 0

常用链接

留言簿(1)

随笔档案

文章分类

文章档案

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜

2007年5月8日

遍历删除vector的中的元素

一般来说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真是设计的强大.

posted @ 2007-05-08 10:43 陈长虹 阅读(5744) | 评论 (4)编辑 收藏

2007年3月31日

一个VIM的脚本

使用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/就可以了,如果启动时候有错误,就下载一个老一点的版本.

posted @ 2007-03-31 10:26 陈长虹 阅读(412) | 评论 (0)编辑 收藏
indent工具参数

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
-pcs -nprs -saf -sai -saw -nsc -nsob -nss -i4 -ts4 -ut
保存在~/.indent.pro,就是默认的indent参数了.

posted @ 2007-03-31 10:12 陈长虹 阅读(995) | 评论 (0)编辑 收藏

2007年3月12日

开张了

从Google上发现了这个C++专门的Blog,发现很不错,有自己写的欲望了,申请了一下,今天开张,希望能记录一些经验,保存一些自己看到的比较好的文章.

posted @ 2007-03-12 15:20 陈长虹 阅读(891) | 评论 (0)编辑 收藏
仅列出标题