C++ Primer Summary

About Header

We use headers to access classes defined for our own applications.

  • Conventionally, header file names are derived from the name of a class defined in that header.
  • The standard library headers typically have no suffix at all. Compilers usually don’t care about the form of header file names, but IDEs sometimes do.
  • Headers should have guards, even if they aren’t (yet) included by another header.
  • Headers should not include using declarations.

About class

A major design of goal of C++ is to let the programmers define their own types that are as easy to use as the built-in types.

About Primitive Built-in Types

  • Use int for integer arithmetic. short is usually too small and in practice, long often has the same size of int. If you data values are larger than the minimum guaranteed size of an int, then use long long.
  • Use double for floating-point computations; float usually does not have enough precision. The precision offered by long double usually is unnecessary.
  • Expression that mix signed and unsigned values can yield surprising results when the signed value is negative.
  • Initialization in C++ is a surprisingly complicated topic.
  • List initialization, When used with variables of built-in type,this form of initialization has one important property: the compiler will not let us list initialize variables of built-in type if the initializer might lead to the loss of information.
    int units_sold{0};//list initialization
    long double  ld = 3.1415926535;//this is copy initialization
    int a{ld}; //error:narrowing conversion required
    int c(ld);//ok:but value will be truncated +this is also an example of direct initialization

About Container

  • use empty() instead of size()==0 to get if the container is empty.
  • use at(i) instead of [i] to get the i-th element;
  • use contain::size_type to get the index of element. size_type is one machine-independent manner. And size_type is an unsigned type.
  • The most common way of using vectors is to define an initially empty vector to which elements are added as their values become at run time.The exception to this rule is if all the elements actually need same values. If differing the element values are needed , it is usually more efficient to define an empty vector.
  • If the vector holds elements of a built-in value type, such as int, then the element initializer has a value of 0. or string as empty string; However, if our vector holds objects that we cannot default initialize, then we must supply an initial element value.
    vector(size,ownTypeElement);
  • C++ programmers use != as a matter of habit.They do so for the same reason that they use iterators rather than subscripts.
  • The prefix version avoids unnecessary work. It increments the value and returns the incremented version.However, the postfix operator must store the original value so that it can return the unincremented value as its result.

About Function

  • Programmers accustomed to programming in C often use pointer parameters to access objects outside a function. In C++,programmers generally use reference parameters instead. And reference parameters that are not changed inside a function should be references to const.
  • Default arguments ordinarily should be specified with the function declaration in an appropriate header.And what’s more is defaults can be specified only if all parameters to the right already have defaults.
  • In general, the inline mechanism is meant to optimize small, straight-line functions that are called frequently.(A 75-line function will almost surely not be expanded inline.)And inline functions normally are defined in headers.

About Member Functions

  • A const following the parameter list indicates that this is a pointer to const. Member functions that use const in this way are const member functions.

  • 代码块高亮

  • 图片链接和图片上传
  • LaTex数学公式
  • UML序列图和流程图
  • 离线写博客
  • 导入导出Markdown文件
  • 丰富的快捷键

快捷键

  • 加粗 Ctrl + B
  • 斜体 Ctrl + I
  • 引用 Ctrl + Q
  • 插入链接 Ctrl + L
  • 插入代码 Ctrl + K
  • 插入图片 Ctrl + G
  • 提升标题 Ctrl + H
  • 有序列表 Ctrl + O
  • 无序列表 Ctrl + U
  • 横线 Ctrl + R
  • 撤销 Ctrl + Z
  • 重做 Ctrl + Y

Markdown及扩展

Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成格式丰富的HTML页面。 —— [ 维基百科 ]

使用简单的符号标识不同的标题,将某些文字标记为粗体或者斜体,创建一个链接等,详细语法参考帮助?。

本编辑器支持 Markdown Extra ,  扩展了很多好用的功能。具体请参考Github.

表格

Markdown Extra 表格语法:

项目 价格
Computer $1600
Phone $12
Pipe $1

可以使用冒号来定义对齐方式:

项目 价格 数量
Computer 1600 元 5
Phone 12 元 12
Pipe 1 元 234

定义列表

Markdown Extra 定义列表语法:
项目1
项目2
定义 A
定义 B
项目3
定义 C

定义 D

定义D内容

代码块

代码块语法遵循标准markdown代码,例如:

@requires_authorization
def somefunc(param1='', param2=0):
    '''A docstring'''
    if param1 > param2: # interesting
        print 'Greater'
    return (param2 - param1 + 1) or None
class SomeClass:
    pass
>>> message = '''interpreter
... prompt'''

脚注

生成一个脚注1.

目录

[TOC]来生成目录:

  • About Header
  • About class
  • About Primitive Built-in Types
  • About Container
  • About Function
  • About Member Functions
    • 快捷键
    • Markdown及扩展
      • 表格
      • 定义列表
      • 代码块
      • 脚注
      • 目录
      • 数学公式
      • UML 图
    • 离线写博客
    • 浏览器兼容

数学公式

使用MathJax渲染LaTex 数学公式,详见math.stackexchange.com.

  • 行内公式,数学公式为: Γ(n)=(n1)!nN
  • 块级公式:

x=b±b24ac2a

更多LaTex语法请参考 这儿.

UML 图:

可以渲染序列图:

Created with Raphaël 2.1.0 张三 张三 李四 李四 嘿,小四儿, 写博客了没? 李四愣了一下,说: 忙得吐血,哪有时间写。

或者流程图:

Created with Raphaël 2.1.0 开始 我的操作 确认? 结束 yes no
  • 关于 序列图 语法,参考 这儿,
  • 关于 流程图 语法,参考 这儿.

离线写博客

即使用户在没有网络的情况下,也可以通过本编辑器离线写博客(直接在曾经使用过的浏览器中输入write.blog.csdn.net/mdeditor即可。Markdown编辑器使用浏览器离线存储将内容保存在本地。

用户写博客的过程中,内容实时保存在浏览器缓存中,在用户关闭浏览器或者其它异常情况下,内容不会丢失。用户再次打开浏览器时,会显示上次用户正在编辑的没有发表的内容。

博客发表后,本地缓存将被删除。 

用户可以选择 把正在写的博客保存到服务器草稿箱,即使换浏览器或者清除缓存,内容也不会丢失。

注意:虽然浏览器存储大部分时候都比较可靠,但为了您的数据安全,在联网后,请务必及时发表或者保存到服务器草稿箱

浏览器兼容

  1. 目前,本编辑器对Chrome浏览器支持最为完整。建议大家使用较新版本的Chrome。
  2. IE9以下不支持
  3. IE9,10,11存在以下问题
    1. 不支持离线功能
    2. IE9不支持文件导入导出
    3. IE10不支持拖拽文件导入


  1. 这里是 脚注内容. ↩

你可能感兴趣的:(c++,C++)