szt1993 发表于 2024-3-26 13:29

c++标准库

本帖最后由 szt1993 于 2024-3-26 13:30 编辑

c++标准库:1、标准库的特性:
[*]C++标准库并不是C++语言的一部分
[*]C++标准库是由类库和函数库组成的集合
[*]C++标准库中定义的类和对象都位于std命名空间中
[*]C++标准库的头文件都不带.h后缀,当然也兼容c语言里面的.h写法
[*]C++标准库涵盖了C库的功能
2、C++编译环境的组成:3、C++标准库预定义了很多常用的数据结构:-<bitset>      -<set>          -<cstdio>
-<deque>         -<stack>      -<cstring>   
-<list>          -<vector>       -<cstdlib>
-<queue>         -<map>          -<cmath>   

代码示例:<font color="rgb(117, 113, 94)">#include <cstdio></font>
<font color="rgb(117, 113, 94)">#include <cstring></font>
<font color="rgb(117, 113, 94)">#include <cstdlib></font>
<font color="rgb(117, 113, 94)">#include <cmath></font>

using namespace std;//所谓命名空间,是一种将程序库名称封装起来的方法,它就像在各个程序库中立起一道道围墙


int main()
{
    <font color="rgb(166, 226, 46)">printf</font>(<font color="rgb(166, 226, 46)">"Hello world!\n"</font>);

    char* p = (char*)malloc(16);

    strcpy(p, <font color="rgb(166, 226, 46)">"TXP"</font>);

    double a = 3;
    double b = 4;
    double c = sqrt(a * a + b * b);

    <font color="rgb(166, 226, 46)">printf</font>(<font color="rgb(166, 226, 46)">"c = %f\n"</font>, c);

    free(p);

    <font color="rgb(166, 226, 46)">return</font> 0;
}


输出结果:root@txp-virtual-machine:/home/txp<font color="rgb(117, 113, 94)"># ./a.out</font>
Hello world!
c = 5.000000

B1lanche 发表于 2024-3-29 11:13

标准库可以多用用,会有很好的提升的

Carina卡 发表于 2024-3-29 12:19

我觉得C++在单片机开发之中,用的还是少一些

Allison8859 发表于 2024-3-29 13:24

其实用C语言就行了,C++少吧

Charlotte夏 发表于 2024-3-29 14:28

这标准库多玩玩挺好的,自己可以少弄点代码了

Belle1257 发表于 2024-3-29 15:31

看着还不错啊,标准库其实就是为了降低代码量的吧

Charlene沙 发表于 2024-3-29 16:32

有些比较常用的,用标准库实现确实不错

Annie556 发表于 2024-3-29 17:45

C++和C语言可以混着用吗?

Candic12e 发表于 2024-3-30 07:06

这种C++的标准库是可以很快的运行吗?

alxd 发表于 2024-3-30 08:10

就用的CSTDIO这差不多

Emily999 发表于 2024-3-30 09:26

其实搞个数学库挺好的,对于数据处理的方面很受用
页: [1]
查看完整版本: c++标准库