本身是不应该关注语法细节的.
_ _ _ _ _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>
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. Thestring class is an instantiation of thebasic_string class template, defined in as:<var style="font-style: normal; color: rgba(0, 0, 176, 1)">typedef</var>basic_string<<var style="font-style: normal; color: rgba(0, 0, 176, 1)">char</var>> string;
Member functions
[**(constructor)**](http://www.cplusplus.com/reference/string/string/string/)
Construct string object(constructor member )
[**operator=**](http://www.cplusplus.com/reference/string/string/operator=/)
String assignment(public member function)
Iterators :
[**begin**](http://www.cplusplus.com/reference/string/string/begin/)
Return iterator to beginning(public member function)
[**end**](http://www.cplusplus.com/reference/string/string/end/)
Return iterator to end(public member function)
[**rbegin**](http://www.cplusplus.com/reference/string/string/rbegin/)
Return reverse iterator to reverse beginning(public member function)
[**rend**](http://www.cplusplus.com/reference/string/string/rend/)
Return reverse iterator to reverse end(public member function)
Capacity :
[**size**](http://www.cplusplus.com/reference/string/string/size/)
Return length of string(public member function)
[**length**](http://www.cplusplus.com/reference/string/string/length/)
Return length of string(public member function)
[**max_size**](http://www.cplusplus.com/reference/string/string/max_size/)
Return maximum size of string(public member function)
[**resize**](http://www.cplusplus.com/reference/string/string/resize/)
Resize string(public member function)
[**capacity**](http://www.cplusplus.com/reference/string/string/capacity/)
Return size of allocated storage(public member function)
[**reserve**](http://www.cplusplus.com/reference/string/string/reserve/)
Request a change in capacity(public member function)
[**clear**](http://www.cplusplus.com/reference/string/string/clear/)
Clear string(public member function)
[**empty**](http://www.cplusplus.com/reference/string/string/empty/)
Test if string is empty(public member function)
Element access :
[**operator[]**](http://www.cplusplus.com/reference/string/string/operator[]/)
Get character in string(public member function)
[**at**](http://www.cplusplus.com/reference/string/string/at/)
Get character in string(public member function)
Modifiers :
[**operator+=**](http://www.cplusplus.com/reference/string/string/operator+=/)
Append to string(public member function)
[**append**](http://www.cplusplus.com/reference/string/string/append/)
Append to string(public member function)
[**push_back**](http://www.cplusplus.com/reference/string/string/push_back/)
Append character to string(public member function)
[**assign**](http://www.cplusplus.com/reference/string/string/assign/)
Assign content to string(public member function )
[**insert**](http://www.cplusplus.com/reference/string/string/insert/)
Insert into string(public member function )
[**erase**](http://www.cplusplus.com/reference/string/string/erase/)
Erase characters from string(public member function)
[**replace**](http://www.cplusplus.com/reference/string/string/replace/)
Replace part of string(public member function )
[**swap**](http://www.cplusplus.com/reference/string/string/swap/)
Swap contents with another string(public member function)
String operations :
[**c_str**](http://www.cplusplus.com/reference/string/string/c_str/)
Get C string equivalent(public member function )
[**data**](http://www.cplusplus.com/reference/string/string/data/)
Get string data(public member function)
[**get_allocator**](http://www.cplusplus.com/reference/string/string/get_allocator/)
Get allocator(public member function)
[**copy**](http://www.cplusplus.com/reference/string/string/copy/)
Copy sequence of characters from string(public member function)
[**find**](http://www.cplusplus.com/reference/string/string/find/)
Find content in string(public member function)
[**rfind**](http://www.cplusplus.com/reference/string/string/rfind/)
Find last occurrence of content in string(public member function)
[**find_first_of**](http://www.cplusplus.com/reference/string/string/find_first_of/)
Find character in string(public member function)
[**find_last_of**](http://www.cplusplus.com/reference/string/string/find_last_of/)
Find character in string from the end(public member function)
[**find_first_not_of**](http://www.cplusplus.com/reference/string/string/find_first_not_of/)
Find absence of character in string
[**find_last_not_of**](http://www.cplusplus.com/reference/string/string/find_last_not_of/)
Find absence of character in string from the end(public member function)
[**substr**](http://www.cplusplus.com/reference/string/string/substr/)
Generate substring(public member function)
[**compare**](http://www.cplusplus.com/reference/string/string/compare/)
Compare strings(public member function )
_ _ _ _ _Chapter 4_ _ _ _ _ __
① vector算是对C中数组的改进? vectorv(6),居然和数组一样用法v[2].
② 显然vector应该是class,有内部成员:
push_back这个成员真好,不像C中那样不可以追加.
vectorV 其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 然后在开始的每一个章节后面加上一些编程规范(当然这个有利有弊了,会限制风格,但是总体利大于弊)
原文链接: https://www.cnblogs.com/tonyho/archive/2011/12/31/2742228.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/39509
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!