`
fei3l
  • 浏览: 7750 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

C++ Primer 学习笔记

阅读更多

1:函数

     组成:

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

     特殊函数:

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

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

 

2:开发

     源码:

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

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

    预处理

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

          如:#include <stdio.h> 该指令告诉预处理器将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 <iostream>


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

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

void commonTest(){
    //dingyi
    /**
     * test dingyi
     */
    std::cout << "/*" << "*/" << std::endl;

    //注视不可输出
//    std::cout << /* "/*" "*/" */ << std::endl;

}

void doWhile(){

    using namespace std;
    int i = 1;

    //9*9口诀
    while( i<10){

        int j = 1;
        while( j <= i){
            string space = i*j >= 10?"  ":"   ";
            std::cout << j << "*" << i << "=" << i*j << space;

            j++;
        }
        std::cout<<std::endl;

        i++;
    }

}

void doFor(){

    using namespace std;

    int i=1;
    int j=1;

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

        string space = i*j >= 10 ? "  ":"   ";

        std::cout << j <<" * "<<i<<" = " << i*j << space;

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

int main(){

    doFor();

    return 0;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics