---
title: "C++ Primer 学习笔记"
author: "fei3l"
date: "2011-04-24T23:33:48Z"
tags: []
categories: ["编程语言"]
slug: "c-primer"
draft: false
lastmod: "2011-04-24T23:33:48Z"
id: 1014516
url: "https://fei3l.iteye.com/blog/1014516"
---

1：函数

     组成：

          返回类型、函数名、形参列表和函数体；

     特殊函数：

          main函数是唯一操作系统显式调用的函数；

          mian函数返回的值对应为系统状态标识符；

 

2：开发

     源码：

          c++源代码由ACSII组成，以文件扩展名加以区分；

          目前支持的文件扩展名有：.cc、.cxx、.cpp、.cp、.c等；

    预处理

          预处理器(cpp)根据以字符#开头的命令修改原始的C程序；

          如：#include &lt;stdio.h&gt; 该指令告诉预处理器将stdio.h中的内容插入至程序文件中，

                从而形成新的 程序文件，通常是以.i作为文件扩展名； 编译： 编译器（ccl）负责

                将文本.i文件翻译成文本.s文件，将.i中的高级命令转换 为汇编中的低级机器语言指

                令，此处将高级语言指令转换为汇编指令；

    汇编：

           汇编器(as)将.s翻译成机器语言指令，并将结果保存于.o结尾的二进制文件中， 其字节

           编码是机器语言指令；

     链接：

            如在hello程序中调用了printf函数，printf是标准的库函数，其存在于prinft.o 的单独

            的预编译目标文件中，而printf必须并入到hello.o程序中，链接器（ld） 就负责处理这

            样的并入操作，并入完成则生成可执行文件；

3:编码

   第一、二章代码：

     #include "header/MainTes.h"  
#include &lt;iostream&gt;

void ioTest(){  
    //定义命名空间  
        using namespace std;

        std::cout &lt;&lt; "Enter two numbers:" &lt;&lt; std::endl;  
        int num1 = 0;  
        int num2 = 0;  
        std::cin &gt;&gt; num1&gt;&gt;num2;  
        std::cout &lt;&lt; "The sum of " &lt;&lt; num1 &lt;&lt; " and " &lt;&lt; num2 &lt;&lt; " is :: " &lt;&lt; num1+num2 &lt;&lt;std::endl;  
}

void commonTest(){  
    //dingyi  
    /\**  
     * test dingyi  
     \*/  
    std::cout &lt;&lt; "/\*" &lt;&lt; "\*/" &lt;&lt; std::endl;

    //注视不可输出  
//    std::cout &lt;&lt; /* "/\*" "\*/" \*/ &lt;&lt; std::endl;

}

void doWhile(){

    using namespace std;  
    int i = 1;

    //9\*9口诀  
    while( i&lt;10){

        int j = 1;  
        while( j &lt;= i){  
            string space = i\*j &gt;= 10?"  ":"   ";  
            std::cout &lt;&lt; j &lt;&lt; "\*" &lt;&lt; i &lt;&lt; "=" &lt;&lt; i\*j &lt;&lt; space;

            j++;  
        }  
        std::cout&lt;&lt;std::endl;

        i++;  
    }

}

void doFor(){

    using namespace std;

    int i=1;  
    int j=1;

    for(; j&lt;=i && i&lt;10 ; j++){

        string space = i\*j &gt;= 10 ? "  ":"   ";

        std::cout &lt;&lt; j &lt;&lt;" * "&lt;&lt;i&lt;&lt;" = " &lt;&lt; i\*j &lt;&lt; space;

        if( i == j){  
            std::cout &lt;&lt; std::endl;  
            i++;  
            j = 0;  
        }  
    }  
}

int main(){

    doFor();

    return 0;  
}