0
点赞
收藏
分享

微信扫一扫

C++ plus6th 1-3章


1.关于函数定义时的省略情形

  • 在函数定义时,如果省略函数前面的返回值类型:在C标准中默认返回int值,但在C++语言中,并没有该规定,其必须有返回值类型。
  • 在函数定义时,如果省略参数列表:在C++中,默认该函数无参数(void),但在C语言中,并无该规定,必须明确表示有无参数列表;
  • main函数必须有返回值,所以即使你定义了main函数的返回值类型为void,编译器同样会在程序结束前隐式添加​​return 0;​​语句。
  • 所以,在函数定义时,为了减少错误的发生,无论C或是C++,我们都要明确所定义函数的返回值类型和参数列表。

2.关于注释符

  • C风格的注释符为​​/* */​​,它可以位于单独行或跨行,但起始和终止符必须配对使用
  • C++风格的注释符为​​//​​,它仅位于单独行(也可位于代码行后面),以​​//​​为起始,行尾为终止符。
  • C++兼容C的注释符,C99以后版本也兼容C++的注释符

3.关于文件扩展名

  • C++源文件的扩展名有:​​.cpp​​​,​​.C​​​,​​.cxx​​,取决于你的C++系统。

4. 关于头文件

  • 在使用C++的输入输出函数(cout和cin)时,在编辑代码前必须包含两句:

​#include <iostream.h>​​ 适用于旧版本C++编译器

或最新版本编译器

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n29" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> #include <iostream>
using namespace std;</pre>

关于头文件的使用,C++旧版本是和C一样的,使用​​.h​​​作为扩展名(例如:#include <iostream.h>),但后来为了区分是C还是C++的头文件,新版C++规定头文件不再添加​​.h​​​的扩展(例如:#include <iostream>),但有些共同的头文件,C++又以在原文件名前添加​​c​​​的形式表示,例如C中的​​math.h​​​,在C++以​​cmath​​表示。




C++ plus6th 1-3章_python


image-20210221160232333


5. 关于命名空间

  • 在使用C++的输入输出函数(cout和cin)时,在编辑代码前必须包含两句:

​#include <iostream.h>​​ (适用于旧版本C++编译器)

或最新版本编译器:(所有函数均默认使用std命名空间)

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n38" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> #include <iostream>
using namespace std;//其作用范围取决于它的位置
...
cout<<"hello!"<<endl;</pre>

或者仅将需要用到的函数在编码前明确使用std命名空间)

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n40" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> #include <iostream>
using std::cout; //或在使用时直接全路径调用
using std::cin;
using std::endl;
...
cout<<"hello!"<<endl;</pre>

6. 关于变量声明和赋值语句

  • 在早期的C语言中,为了方便管理,一般将一段程序中的所有变量声明集中放在程序开头位置处,但后来的C++及C99以后,规定变量声明应该紧挨着变量第一次使用前的位置.

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n46" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> ...
int var;
var = 10;
...</pre>

    • 赋值操作符​​=​​可以串联使用
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c" cid="n50" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> int Var1,Var2,Var3;
    Var1 = Var2 = Var3 = 10;</pre>

    • 赋值操作符​​=​​可以自引用

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c" cid="n54" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> Var = Var - 1;</pre>

    7. cout和printf()

    • 在C语言中,利用printf()函数输出一个数字时,需要用%d明确告知,但cout会自动判别并自动输出

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c" cid="n59" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> printf("Printing a string: %s", "25");
    printf("Printing a string: %d", 25);</pre>

    C++中:

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n61" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> int Var = 25;
    cout << Var;</pre>

    此处,之所以cout可以识别Var,是因为整形变量对​​<<​​操作符进行了符号重载,其完成了2件事:一是取得变量Var的二进制数值大小 ;二是将该数值转化成相应的数字字符串并输出.cin同理.

    • 另外通过​​hex,oct​​关键字,可以改变cout输出数字的进制(默认输出10进制dec)。例如:

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n66" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> #include <iostream>
    using namespace std;
    int main()
    {
    using namespace std;
    int chest = 42;
    int waist = 42;
    int inseam = 42;
    cout << “Monsieur cuts a striking figure!” << endl;
    cout << “chest = “ << chest << “ (decimal)” << endl;
    cout << hex; // manipulator for changing number base
    cout << “waist = “ << waist << “ hexadecimal” << endl;
    cout << oct; // manipulator for changing number base
    cout << “inseam = “ << inseam << “ (octal)” << endl;
    return 0;
    }

    输出:
    Monsieur cuts a striking figure!
    chest = 42 (decimal)
    waist = 2a hexadecimal
    inseam = 52 (octal)</pre>

    However, if you omitted the using directive and instead used std::cout, std::endl, std::hex, and std::oct, you could still use plain hex as the name for a variable.

    8. 关于变量名

    C++中:

    • 变量名仅能由字母、数字和下划线组成,且数字不能开头。
    • 以双下划线开头或单下划线加大写字母开头的变量是系统保留的,用户不得使用.
    • 以单下划线开头命名的变量也是系统保留的,一般视为全局变量,用户不得使用.
    • 在C语言中,变量名只有前63个字符是有意义的。也就是说两个变量名,如果他们的前63个字符是相同的,则C编译器认为该两个变量就是同一个。而在C++中,变量名长度没有限制,所有字符均有意义。

    9.关于整形



    C++ plus6th 1-3章_编程语言_02


    image-20210226114436919


    在任一系统中,short\int\long必须满足以下条件

    • short至少16位宽
    • int位宽不得小于short
    • long至少32位,且不得小于int
    • long long至少64位,且不得小于long

    整型变量类型的选择:

    • int是最常选择的,因为计算机对它的处理效率最高
    • 如果你能确定变量的值不会取负,那就选择unsigned类型的。
    • 如果变量的值比较大(大于16位数所能表示),那就选long型
    • 如果需要考虑到内存资源消耗,特别是需要定义一个很大的整型数组时,那就选short
    • 如果你仅仅使用单字节,那就选char。

    来自limits.h文件的符号常量:

    符号常量

    含义

    CHAR_BIT

    char类型的位数

    CHAR_MAX

    Maximum char value

    CHAR_MIN

    Minimum char value

    SCHAR_MAX

    Maximum signed char value

    SCHAR_MIN

    Minimum signed char value

    UCHAR -MAX

    Maximum unsigned char value

    SHRT_MAX

    Maximum short value

    SHRT_MIN

    Minimum short value

    USHRT_MAX

    Maximum unsigned short value

    INT_MAX

    Maximum int value

    INT_MIN

    Minimum int value

    UINT_MAX

    Maximum unsigned int value

    LONG_MAX

    Maximum long value

    LONG_MIN

    Minimum long value

    ULONG_MAX

    Maximum unsigned long value

    9.1 关于赋值

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n155" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> int owls = 101; // traditional C initialization
    int wrens(432); // alternative C++ syntax, set wrens to 432</pre>

    9.2 关于自定义符号常量

    在C语言中,我们一般会利用​​#define​​​语句来定义自己的符号常量,但在C++中,我们一般会使用​​const​​关键字来定义一个符号常量(名字一般采用全大写字母),并在定义的同时进行赋值。因为后者可以指定常变量的数据类型,可以控制作用范围,可以修饰更多复杂数据类型(数组、结构体),所以比define宏更具优势。

    当然在C语言中也可以使用const关键字,但其与C++中的最主要的区别:一是在于作用范围;二是在C++中(不在C中),可以使用const值来定义一个数组的大小。

    2.0版C++之前,和C语言一样,用int型来存储字符常量的值(但字符变量仍用char型存储),但在之后C++就用char型来存储字符常量的值了。

    字符常量的表示方法:

    • 单引号加字符:例如 ‘a’
    • 反斜杠加字母表示特殊字符:​​\a​​(响铃),​​\n​​(换行),​​\r​​(回车),​​\b​​(回退)
    • 反斜杠加八进制或十六进制数字:​​\032​​或​​\x1a​​表示CTRL+Z
    • \u加8个16进制数 或 \U加16个16进制数(这些数字代表ISO 10646字符集编码):\u00E2 代表 â

    9.3 关于数字常量的默认适配类型

    • 对于单纯的整型数字来说,如果不加任何修饰,则一般认为其为十进制整数,如2000;
    • 如果在数字后添加​​l​​或​​L​​则代表此数字为long型,添加​​u​​或​​U​​则代表unsigned
    • 因为小写的l容易与1混淆,一般使用​​L​​​,​​UL​​​或​​LU​​都代表unsigned long意思
    • 在C++中,默认会选择最小适配的整数类型存储给定的整型常量
    • 对于十进制整数:依次匹配​​int​​、​​long​​、​​unsigned long​​;
    • 对于八进制或十六进制:依次匹配​​int​​、​​unsigned int​​,​​long​​、​​unsigned long​​;

    9.4 关于char

    不同关于int,long型,char既不明确代表signed char,也不明确代表 unsigned char,不同的系统选择也不同,所以为了程序的兼容性,开发者可以自己明确。

    因为char只有8位,最多仅表示256个不同的字符,在系统使用的字符集超过这个数后,char型就不足以表示全部的字符了。为了解决该问题,C++使用​​wchar_t​​类型来表示扩展的字符集,它本质上是16位二进制整数,既可以是unsigned short,也可以是int类型。

    • C++采用在字符或字符串前缀 ‘L’ 表示宽字符,例如:L’P’ 或 L”tall”
    • C++使用wcout 和 wcin来处理wchar_t类型的字符流

    10. 关于浮点型



    C++ plus6th 1-3章_编译器_03


    image-20210226114704117


    • C++中有3种浮点型数据:float(32位)、double(64位)、long double(80-128位)
    • 在C语言中的float.h或C++中的cfloat头文件,规定了实数有效数字和尾数等的值:


    C++ plus6th 1-3章_python_04


    image-20210225152037877


    • 在C++中有两种表示方法:一是固定小数点的方式1212.3456,二是使用E或e的方式12.123456e2;使用cout命令输出实数时需要设置输出方式,为此:

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n206" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> cout.setf(ios_base::fixed, ios_base::floatfield) //fixed-point
    cout.setf(ios::fixed, ios::floatfield) //fixed-point C++老版本 </pre>

    10.1 关于浮点常数

    • 默认浮点常数采用double型存储,若在常量后缀f或F,则采用float型存储,若在常量后缀l或L则用long double型存储。因为小写的l很像数字1,所以一般使用L。
    • float最大只能保证6位有效数字的精度,超过6位有效数字时,建议使用duoble型

    10.2 关于浮点数的运算

    • 除法(/):若2个操作数均为整数,则结果为整数;若至少有一个操作数为浮点数,则结果为浮点数。
    • 取余(%):左右操作数必须为整数,否则报错!

    10.3 关于类型转换

    类型转换发生在赋值、运算表达式和参数传递时:

    • 赋值时的转换:整数向浮点数转换时后面添加小数0;浮点数向整数转换时截断后面的小数,但若超过整数范围时无确定意义;
    • 表达式中的转换:C++将自动将​​bool,char,unsigned char,signed char,short,unsigned short​​的值转化为​​int​​型值再做计算(true一般转为1,false转化为0)。若short 和int的位数一样,则unsigned short转化为unsigned int。类似的wchar_t类型将自动转化为能包含它大小的最小如下类型:int,unsigned int,long,unsigned long。

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n226" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> short chickens = 20; //line 1
    short ducks =35; //line 2
    short fowl = chickens + ducks; //line 3</pre>

    在执行第三条语句时,计算机倾向于先将chickens和ducks转化为int型,求得结果后在转化为short型赋值给fowl变量。因为对CPU而言,int型是计算效率最快的一种数据类型。

    简而言之,当表达式存在两种不同类型的数据进行运算时,数值范围小的将自动向数值范围大的转化:



    C++ plus6th 1-3章_编程语言_05


    image-20210226110207482


    • 传参时的转换:一般来说,参数的类型转换由函数原型中声明的进行,但C++将自动转换char,short(包含signed和unsigned)型的参数为int型。同时为了兼容经典C,自动将float转化成double。

    10.4 强制类型转换

    在C++中有多种形式的强制类型转换:(以将int型的thorn变量转化为long型为例)

    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="c++" cid="n235" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> (long)thron //C语言形式
    long(thron) //C++形式,使之看起来像函数调用
    static_cast<long> (thron) //</pre>

    强制类型转换并不实际改变原变量的类型,他只是生成一个临时数值。

    举报

    相关推荐

    0 条评论