###废话不多说,直接上使用方法!
***
声明规则:* 类型 变量名[数组大小]*
***
#### 1、整型
整形数组初始化
`int arr[4]; `
带值的初始化
`int arr2[4] = {1,2};`
***
#### 2、浮点型
浮点数与双精度浮点数数组初始化
`float f1[2];`
`double f2[2];`
带值的初始化
`float f1[2] = {1.1f, 1.2f};`
`double f1[2] = {1.1f, 1.2f};`
***
#### 3、字符串
字符串数组初始化
`std::string str[2];`
带值的初始化
`std::string str2[3] = {"www","copycool","cc"};`
***
以下是一些简单的测试代码,可以直接复制运行,记得输出,不然会报错变量未使用!!!
```C++
#include <iostream>
#include <string>
int main(int argc, const char * argv[]) {
int arr[4]; // 声明 --- 默认值0,0,0,0
int arr2[4] = {1,2}; // 赋值初始化 --- 值1,2,0,0
// string类型
std::string str[2]; // 默认值{"",""}
std::string str2[3] = {"www","copycool","cc"};
// 浮点
float f1[2];
float f2[3] = {1.1f, 2.2f, 3.3f};
double d1[2];
double d2[3] = {1.1, 2.2, 3.3};
return 0;
}
```
> *1、不要在大小的地方写变量!!*
> *2、创建string,记得引入,不然会报错!!*
> *3、还有其他基本类型,short,long之类的同理*