C++学习总结(九)——C++数组array vector tuple

本文总结了C++中的三种数组类型:array作为静态大小的栈上数组,vector则作为动态大小、内存连续的堆上数组,方便管理不规则数据。而tuple则是用于存储不同类型的静态数组,其元素类型一旦确定必须赋值相应类型。
摘要由CSDN通过智能技术生成

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>
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值