本身是不应该关注语法细节的.
________________________________Chapter 3____________________________
① bool型在C中有(那个标准开始的忘了,C primer plus中有),在C++中更有.
② 字符串的终止会被空白符终止, 空白符:Tab,换行,空格.其实都是空格的一种形式.
③ 初值的赋予注意:eg string first_name = "???"; String 类型应该是对C语言中用数组来表示字符串的改进吧.
④ String用法远比C中舒服.可以加但是不可以减 还可以直接比较时候相等.
⑤ >> 和 << 运算符的应用. S>>X 从S读取到X.
⑥ 终止输入符号: Control + Z 然后按 Enter. 在Linux中的 Control + D
⑦命名的开始下划线最好不用.
⑧再次强调定义时初始化.
⑨对于类型转换的安全性. 在嵌入式编程中很重要的一点,.很多时候总是用unsigned,但是需要注意范围.
__________________________________________________________________________
下面则是引用http://www.cplusplus.com/reference/string/string/中的string中参考
String class
String objects are a special type of container, specifically designed to operate with sequences of characters.
Unlike traditional c-strings, which are mere sequences of characters in a memory array, C++ string objects belong to a class with many built-in features to operate with strings in a more intuitive way and with some additional useful features common to C++ containers.
The string class is an instantiation of the basic_string class template, defined in <string> as:
typedef basic_string<char> string;
Member functions
operator= | String assignment (public member function) |
Iterators:
begin | Return iterator to beginning (public member function) |
end | Return iterator to end (public member function) |
rbegin | Return reverse iterator to reverse beginning (public member function) |
rend | Return reverse iterator to reverse end (public member function) |
Capacity:
size | Return length of string (public member function) |
length | Return length of string (public member function) |
max_size | Return maximum size of string (public member function) |
resize | Resize string (public member function) |
capacity | Return size of allocated storage (public member function) |
reserve | Request a change in capacity (public member function) |
clear | Clear string (public member function) |
empty | Test if string is empty (public member function) |
Element access:
operator[] | Get character in string (public member function) |
at | Get character in string (public member function) |
Modifiers:
operator+= | Append to string (public member function) |
append | Append to string (public member function) |
push_back | Append character to string (public member function) |
assign | Assign content to string (public member function ) |
insert | Insert into string (public member function ) |
erase | Erase characters from string (public member function) |
replace | Replace part of string (public member function ) |
swap | Swap contents with another string (public member function) |
String operations:
c_str | Get C string equivalent (public member function ) |
data | Get string data (public member function) |
copy | Copy sequence of characters from string (public member function) |
find | Find content in string (public member function) |
rfind | Find last occurrence of content in string (public member function) |
find_last_of | Find character in string from the end (public member function) |
find_last_not_of | Find absence of character in string from the end (public member function) |
substr | Generate substring (public member function) |
compare | Compare strings (public member function ) |
_____________________________Chapter 4_____________________________________
① vector算是对C中数组的改进? vector<int>v(6),居然和数组一样用法v[2].
② 显然vector应该是class,有内部成员:
push_back这个成员真好,不像C中那样不可以追加.
vector<int>V 其size成员在初始化时是0.
begin和end成员也不错.....
看来这个确实比C舒服.
③sort排序
__________________________________________________________________________
__________________________________Chapter 5________________________________
★ 以前学语言都是直接边学习边编写程序的,在编译运行的时候才去分析错误IDE或工具链给出的错误和警告,在这本书中直接用一个章节来写
在程序编译链接运行时有可能出现的错误,以及不同类型的错误.
★ 最为难以解决的应该是运行时错误:
最经典的其一是 除数为0,当我们的除以的变量有可能为0时,可能会忘记将其判断一下在处理.
★ 从调用者必须检查参数到方式必须检查参数, 需要编写函数的作者对传入参数进行检查.经典的是 if(p == NULL) return EXIT_FAILURE;
★ 异常处理try{} catch{},C语言中的异常处理用的是实现goto的longjmp()和setjmp() ,当然Linux内核中的错误处理直接就是用goto来完成.[参考书本Linux Device Drivers 3e, Page37
]
★ 调试.记得在<<C语言深度解剖>>里面作者说不要使用printf来查看变量而是应该看Memory或者调试.说得多好.其实开始学编程就该如此学习.而不是来不来习惯用Printf
___________________________________自己的想法_______________________________________
开始学编程的时候就该慢慢的一点点学会使用PC-Lint 然后在开始的每一个章节后面加上一些编程规范(当然这个有利有弊了,会限制风格,但是总体利大于弊)