1.Boost:array,头文件内容
2.boost:array使用案例
#include<boost/array.hpp>
//boost所属的头文件
#include
<iostream>
#include
<string>
using
namespace
std;
//表示使用boost库,当不加此句时,调用的时候要加上boost前缀
using
namespace
boost;
void
main()
{
array <int,
5> barray = { 1, 2, 3, 4, 5 };
barray[0] = 10;
barray.at(4)
= 20;
int *p
= barray.data();//存储数组的指针
cout <<
"-----循环输出结果---------"
<< endl;
for (int
i = 0;
i <
barray.size();i++)
{
cout <<
barray[i]
<< " " <<
p[i]
<< endl;
}
array<string,
3> cmd = {
"calc",
"notepad",
"tasklist" };
cout <<
"-------size()--------" <<
endl;
cout <<
"size = " <<
barray.size()
<< " max_size ="<<
barray.max_size()
<< endl;
cout <<
"-------iterator------" <<
endl;
array<int,
5>::iterator
ibegin =
barray.begin();
array<int,
5>::iterator
iend =
barray.end();
for (;ibegin
!= iend;
ibegin++)
{
cout << *ibegin
<< endl;
}
cout <<
"-------==操作--------"
<< endl;
array <int,
5> barray2 = { 1, 2, 3, 4, 8 };
array <int,
5> barray3 = { 1, 2, 3, 4, 8 };
array <int,
5> barray4 = { 11, 12, 13, 14, 18 };
//结果是1,表示两者内容相等
cout << (barray2
== barray3) <<
endl;
cout << (barray3
== barray4) <<
endl;
cout <<
"-------at()操作--------"
<< endl;
cout <<
barray2.at(1)
<< endl;
cout <<
"-------[]操作--------"
<< endl;
cout <<
barray2[1] <<
endl;
cout <<
"-------front()操作--------"
<< endl;
cout <<
barray2.front()
<< endl;
cout <<
"-------back()操作--------"
<< endl;
cout <<
barray2.back()
<< endl;
cout <<
"-------swap()操作--------"
<< endl;
cin.get();
}