码迷,mamicode.com
首页 > 编程语言 > 详细

c++ primer 学习笔记(1): 第1-5章

时间:2016-05-07 08:31:22      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

reference link:http://blog.csdn.net/yanglusheng/article/details/51123513

第一章 开始

1.输入输出 
流:随着时间的推移,字符是顺序生成或消耗的;

<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">std:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:cout<<<span class="hljs-string" style="box-sizing: border-box;">"Hello World"</span><<std</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:endl</span>;</a></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li></ul>

<<运算符接受两个运算对象,左侧必须是ostream,右侧是要打印的值,计算结果返回ostream对象中。上述使用两次<<运算符,第一次运算结果成了第二次的左侧对象。 
Note:在写重载<<运算符是要返回ostream& 
endl效果:结束当前行,并将与设备关联的缓冲区中的内容输出到设备中。 
2.读取数量不定的输入数据

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span>(cin>><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">value</span>){}
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//对于windows结束方式是Ctrl+Z</span></a></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li></ul>

第二章 变量和基本类型

1.内置类型(算术类型和空类型) 
c++11定义了long long 
2.signed和unsigned 
表达式带有无符号和有符号类型时,会出现异常结果。因为带符号会自动转为无符号类型。 
3.字符串字面值的实际长度比它的内容多1; 
4.变量声明和定义

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">extern</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> i;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//声明而非定义i</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> j;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//声明并定义了j</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//变量只能被定义1次,可被多次声明</span></a></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li></ul>

Note:如果要在多个文件中使用同一个变量,必须将声明和定义分离,定义且只能出现在一个文件中,其它文件要使用必须对其进行声明,不能重复定义。 
5.const对象必须初始化,之后不能改变 
6.顶层const 
指针本身是一个对象,本身是常量是顶层const 
指针可以指向另一个对象,所在对象是个常量是底层const 
7.constexpr和常量表达式 
C++11规定运行将变量声明为constexpr类型由编译器来验证变量值是否是一个常量表达式。 
8.auto和decltype

第三章 字符串、向量、数组

1.使用getline读取一整行(保留空格) 
2.cctype头文件中标准库函数关于字符的操作 
3.C++11中for(auto c:str)

<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">string</span> s(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Hello World!"</span>);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">decltype</span>(s.size()) punct_cnt=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span>(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">auto</span> c:s)
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span>(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">ispunct</span>(s))++punct_cnt;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//统计符合数</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span>(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">auto</span> &c:s)
    c=<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">toupper</span>(c);<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//小写转大写</span></a></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">4</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">5</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">6</a></span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">4</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">5</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">6</a></span></li></ul>

4.可以定义存放指针的数字,但不可以定义存放引用的数组;

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> *ptrs[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>];<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//含有10个整型指针的数组</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> &refs[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>];<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//错误:不存在引用的数组</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> (*parray)[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>]=&arr;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//指向含有10个整数的数组</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> (&arrref)[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>]=arr;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//引用一个含有10个整数的数组</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> *(&arry)[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>]=ptrs;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//arry是数组的引用,该数组含有10个指针</span></a></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">4</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">5</a></span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">4</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">5</a></span></li></ul>

5.C++11引入begin和end

<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> ia[]={<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>};
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*beg</span>=begin(ia);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*last</span>=end(ia);<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>指向尾元素下一个位置</a></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li></ul>

6.数组下标可以是负号

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> ia={<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>};
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> *p=&ia[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> k=p[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>];<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//等价于*(p+1),等价于ia[3]</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> j=p[-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>];<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//等价于ia[0]</span></a></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">4</a></span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">1</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">2</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">3</a></span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;">4</a></span></li></ul>

第四章 表达式

1.多用*iter++,返回当前指向值,然后一到下一位 
2.位运算符:<< ,>>,&,|,~操作 
3.类型转换 
static_cast 
const_cast 
reinterpret_cast

第五章 语句

1.try语句块

<code class="hljs r has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background-image: initial; background-attachment: initial; background-color: transparent; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-family:Microsoft YaHei;"><a target=_blank href="http://blog.csdn.net/u011534057/article/details/51334692" style="color: rgb(0, 0, 0); text-decoration: none; font-size: 20px; line-height: 30px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">try</span>{
}catch()
{
}catch()
{
}
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span></a></span></code>

c++ primer 学习笔记(1): 第1-5章

标签:

原文地址:http://blog.csdn.net/u011534057/article/details/51334719

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!