1. 1
    2
    warning: backslash and newline separated by  
    space int colAndrowArray[3][3]= \
    此类换行错误,删除反斜杠\后面的空格,就不会有waring了。

  2. 两种换行方式 添加\或者 双引号""

    1
    2
    3
    4
    5
    cout << "Hello \
    World" << endl;

    cout << "Hello "
    "World" << endl;

  3. ++startValue 优于startValue++。

  4. true is 1 and false is 0

  5. string vs string.h 一般来说,.h后缀都是c的头文件,与其相对应的不加.h的都是c++的头文件,比如#include <iostream.h>#include <iostream>,前者是c的头文件,后者是c++的头文件,也就是c++没有.h的扩展名,一般后者都是前者的升级版本。 在c++标准化的过程中,为了表示头文件来源于c,有时也在前面加上c,比如cmath就来源于math.h但是stringstring.h没有这样的关系,string.hc处理c字符串的函数库,而stringc++的字符串类的头文件,二者没有任何关系。string也不是string.h的升级版

  6. strcpy(s1, s2); :复制字符串 s2 到字符串 s1。

  7. .c_str: c_str()方法是返回一个C语言字符串的指针常量(即可读不可改变),内容与调用此方法的原字符串相同。即通过c_str()方法,补充C中没有string类型的问题,,通过STRING类对象的成员函数c_str()string对象转换为c中字符串的样式。 e.g.

    1
    2
    3
    char schar[5]={'\0'};
    string cpstr= ("1234");
    strcpy(schar,cpstr.c_str);

  8. 枚举变量初始化也用int (但实际上还是数字,输入的时候还是使用数字)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    	int main()
    {
    enum DaysOfWeek
    {
    Sunday = 0,
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday
    };
    int dayInput = Sunday;
    cin >> dayInput;
    /*enter a number for a day (Sunday=0)*/
    }
    注意上述 输入0代表Sunday,详见程序清单6.5

  9. vscode in wsl2 error: premission denied. solution:

    1
    sudo chown -R myuser /path/to/folder
    note that: for local@host, myuser --> local; /path/to/folder is the path of the folder, local@host: ~/workfolder, /path/to/folder --> ~/workfolder. e.g. sudo chown -R local ~/workfolder

  10. 主函数的两个子函数之间不会传递变量,e.g.:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    int main()
    {
    int numBer=0;
    cin >> numBer;
    if (numBer==1)
    {
    int num2=0;
    cin >> num2;
    }
    int num3=0;
    cin >> num3;
    if (num3==12)
    {
    cout << num3 + num2 << endl;
    }
    }
    上述程序运行出错,显示第二个if函数中变量num2未定义,因为num2是在第一个if子函数中,不会作用到第二个中。

  11. 使用break 退出当前循环;使用return 退出当前函数模块。

  12. while(Integer)的循环,如果Integer 的值为-1,这个while 循环会执行吗? 理想情况下,while 循环表达式应为布尔值true 或false,否则这样解读:零表示false,非零表示true。由于−1 不是零,因此该while 条件为true,循环将执行。如果希望仅当Integer 为正数时才执行循环,可编写表达式while(Integer>0)。这种规则适用于所有的条件语句和循环。