C++新类型数组:
1.array静态数组大小在定义时固定,位于栈上。
#include<iostream>
#include<array>
#include<string>
void main1()
{
double db[4] = {1.1,2.2,3.3,4.4};
std::array<double,3> dbnew = { 10.1,10.2,10.3 };
for (auto a:dbnew)
{
std::cout <<a<< std::endl;
}
std::cin.get();
}
void main()
{
std::array<std::string, 4> string1 = { "calc","notepad","tasklist","ipconfig" };
std::string str1, str2;
std::string str3 = str1 + str2;
for (auto a:string1)
{
std::cout << a << std::endl;
system(a.c_str());
}
std::cin.get();
}
2. vector动态数组大小可变,位于堆上,可以通过接口函数进行删改。 用于管理不规则的树状结构,实现动态无规则,内存连续。
3. tuple静态数组,包含不同的类型,类型固定后必须赋值为相应的类型。
#include<iostream>
#include<tuple>
#include<string>