Fork me on GitHub

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

C++整理

编译
将目标文件预处理、汇编、编译并链接形成可执行文件
g++ xxx 默认输出 a.out
g++ xxx -o yyy 指定输出到 yyy

数据变量
数组
vector容器使用:

include

vectora 创建一个动态数组a,a的默认初值为0
vectorb(a) 将a中的元素复制到b中
vetcora(100) 将数组a的元素定义为100个,默认初始值为0
vectora(100,6) 定义100个值为6的元素
vectora(10,"null") 定义10个值为null的元素

1.a.push_back(100) 在尾部加入一个值为100的元素
2.a.size() 返回数组中元素的个数
3.bool isEmpty=a.empty() 判断a是否为空,若为空返回true,若不为空则返回false
4.cout<<a[0]<<endl 输出数组的大小
5.a.insert(a.begin+i,k) 在第i个元素前插入k
6.a.insert(a.end(),10,5) 在末尾插入10个值为5的元素
7.a.pop_back 删除末尾元素
8.a.erase(a.begin()+i,a.begin()+j) 将[i,j-1]的元素都删除
9.a.erase(a.begin()+i) 将第i+1个元素删除
10.a.resize(n) 将数组重置为n个元素
11.a.clear() 清空数组
12.reverse(a.begin(),a.end()) 将数组逆转
13.sort(a.begin(),a.end()) 将数组从小到大排序
const vector vec; # vec为常向量变量
const vector & vec; # vec 为常向量引用变量,接收指针

字符串
c_str()是Borland封装的String类中的一个函数,它返回当前字符串的首字符地址
字符串比较,(返回值>0)str1大于str2,依次类推
int strcmp(const char *str1, const char *str2)

posted @ 2022-11-07 20:51  365/24/60  阅读(25)  评论(0编辑  收藏  举报