跳至主要内容

博文

【转】详细解说STL string

详细解说STL string 0 前言: string 的角色 1 string 使用 1.1 充分使用string 操作符 1.2 眼花缭乱的string find 函数 1.3 string insert, replace, erase 2 string 和 C风格字符串 3 string 和 Charactor Traits 4 string 建议 5 小结 6 附录 7 参考文章 0 前言: string 的角色 C++ 语言是个十分优秀的语言,但优秀并不表示完美。还是有许多人不愿意使用C或者C++,为什么?原因众多,其中之一就是C/C++的文本处理功能太麻烦,用起来很不方便。以前没有接触过其他语言时,每当别人这么说,我总是不屑一顾,认为他们根本就没有领会C++的精华,或者不太懂C++,现在我接触perl, php, 和Shell脚本以后,开始理解了以前为什么有人说C++文本处理不方便了。 举例来说,如果文本格式是:用户名 电话号码,文件名name.txt Tom 23245332 Jenny 22231231 Heny 22183942 Tom 23245332 ... 现在我们需要对用户名排序,且只输出不同的姓名。 那么在 shell 编程 中,可以这样用: awk ' {print $1} ' name.txt | sort | uniq 简单吧? 如果使用C/C++ 就麻烦了,他需要做以下工作: 先打开文件,检测文件是否打开,如果失败,则退出。 声明一个足够大得二维字符数组或者一个字符指针数组 读入一行到字符空间 然后分析一行的结构,找到空格,存入字符数组中。 关闭文件 写一个排序函数,或者使用写一个比较函数,使用qsort排序 遍历数组,比较是否有相同的,如果有,则要删除,copy... 输出信息 你可以用C++或者C语言去实现这个流程。如果一个人的主要工作就是处理这种类似的文本(例如做apache的日志统计和分析),你说他会喜欢C/C++么? 当然,有了STL,这些处理会得到很大的简化。我们可以使用 fstream来代替麻烦的fopen fread fclose, 用vector 来代替数组。最重要的是用 string 来代替char *...

【转】ethernet 取值

EtherType 是以太帧里的一个字段,用来指明应用于帧数据字段的协议。根据 IEEE802.3,Length/EtherType 字段是两个八字节的字段,含义两者取一,这取决于其数值。在量化评估中,字段中的第一个八位字节是最重要的。而当字段值大于等于十进制值 1536 (即十六进制为 0600)时, EtherType 字段表示为 MAC 客户机协议(EtherType 解释)的种类。该字段的长度和 EtherType 详解是互斥的。 该类字段值取自 IEEE EtherType 字段寄存器。EtherType 字段是个极限空间,因此其分配是有限的。只有开发新的数据传输协议的人员需要使用 EtherType 字段,而不管他们实际上是否真正生产任何设备。IEEE RAC EtherType 字段批准权威机构负责检查和批准 EtherType 字段。 知名协议已经分配了 EtherType 值,下面表格中列出了 EtherType 字段中常用值及其对应的协议: Ethertype(十六进制) 协议 0x0000 - 0x05DC IEEE 802.3 长度 0x0101 � 0x01FF 实验 0x0600 XEROX NS IDP 0x0660 0x0661 DLOG 0x0800 网际协议(IP) 0x0801 X.75 Internet 0x0802 NBS Internet 0x0803 ECMA Internet 0x0804 Chaosnet 0x0805 X.25 Level 3 0x0806 地址解析协议(ARP : Address Resolution Protocol) 0x0808 帧中继 ARP (Frame Relay ARP) [RFC1701] 0x6559 原始帧中继(Raw Frame Relay) [RFC1701] 0x8035 动态 DARP(DRARP:Dynamic RARP) 反向地址解析协议(RARP:Reverse Address Resolution Protocol) 0x8037 Novell Netware IPX 0x809B EtherTalk 0x80D5 IBM SNA Service...

【转】Ether Types

Ether Types (last updated 2008-09-09) NOTE: Please see [RFC5342] for current information and registration procedures. This registry will be revised soon and will be replaced with up-to-date information. Many of the networks of all classes are Ethernets (10Mb) or Experimental Ethernets (3Mb). These systems use a message "type" field in much the same way the ARPANET uses the "link" field. If you need an Ether Type, contact: IEEE Registration Authority IEEE Standards Department 445 Hoes Lane Piscataway, NJ 08854 Phone +1 732 562 3813 Fax: +1 732 562 1571 Email: <ieee-registration-authority& ieee.org > http://standards.ieee.org/regauth/index.html The following list of EtherTypes is contributed unverified information from various sources. Another list of EtherTypes is maintained by Michael A. Patton and is accessible at: <URL: http://www.cavebear.com/CaveBear/Ethernet/ > <URL: ftp://ftp.cavebear.com/pub/Ethernet-codes > Assign...

【转】cs8900移植问题及解决

标签: 移植 cs8900 问题    [ 推送到技术圈 ] 版权声明: 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://ironpeak.blog.51cto.com/439173/100484 移植主要是参考该网页: http://www.cublog.cn/u2/63560/showart_514147.html 我的内核是2.6.24.4 以下是我移植过程存在的一些问题: 内核启动信息: Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)                   Unable to handle kernel paging request at virtual address e000030a              pgd = c0004000                                                                  [e000030a] *pgd=00000000...

【转】u盘驱动过程(linux-2.6.24)

标签: u盘 驱动 过程    [ 推送到技术圈 ] 版权声明: 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://ironpeak.blog.51cto.com/439173/100490 u盘驱动过程(linux-2.6.24) 第一次编译出的问题: [root@/]#usb 1-1: new full speed USB device using s3c2410-ohci and address 4     usb 1-1: device descriptor read/64, error -62                                    usb 1-1: device descriptor read/64, error -62                                    usb 1-1: new full speed USB device using s3c2410-ohci and address 5              usb 1-1: device descriptor read/64, error -62      ...