cout
尽量避免出现这样的代码:
char b[3]={'c','+','+'};
cout<<b<<endl;
cout
输出字符串是根据'\0'
判断结束输出的,所以可能输出乱码
cout
输出顺序从左到右,计算顺序从右到左,如:
int a = 4;
cout<<a<<a++<<endl;//输出54
动态内存
c++关于动态内存有new
和delete
两个操作:(T是任意类型名)
- 单个数据:
T *p = new T(val);//val指定值
delete p;
- 分配一维和二维内存:
//一维:N代表元素个数
T *A = new T[N]
//二维:
T**Matrix;
Matrix = new T*[row]; //给一维指针开辟空间
for(i = 0;i<row;i++)
Matrix[i] = new T[col]; //第二维空间开辟
- 释放一维和二维内存:
//一维:
delete [] A
//二维:
for(int i = 0;i < row;i++){
delete [] Matrix[i];
}
delete [] Matrix;