日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

QQ郵箱

 步芝 2014-12-29
Array是一個(gè)順序容器,和其他標(biāo)準(zhǔn)容器相比它的特點(diǎn)是容器的大小固定,順序存儲(chǔ)。

1array的構(gòu)造函數(shù)

array();

arrayconst array & right);

2array的成員變量
                                                              
[L]Type Definition[/L]
    
[L]Description[/L]
    
[L]array::const_iterator[/L]
    
[L]The type of a constant iterator for  the controlled sequence.[/L]
    
[L]array::const_pointer[/L]
    
[L]The type of a constant pointer to an  element.[/L]
    
[L]array::const_reference[/L]
    
[L]The type of a constant reference to an  element.[/L]
    
[L]array::const_reverse_iterator[/L]
    
[L]The type of a constant reverse  iterator for the controlled sequence.[/L]
    
[L]array::difference_type[/L]
    
[L]The type of a signed distance between  two elements.[/L]
    
[L]array::iterator[/L]
    
[L]The type of an iterator for the  controlled sequence.[/L]
    
[L]array::pointer[/L]
    
[L]The type of a pointer to an element.[/L]
    
[L]array::reference[/L]
    
[L]The type of a reference to an element.[/L]
    
[L]array::reverse_iterator[/L]
    
[L]The type of a reverse iterator for the  controlled sequence.[/L]
    
[L]array::size_type[/L]
    
[L]The type of an unsigned distance  between two elements.[/L]
    
[L]array::value_type[/L]
    
[L]The type of an element.[/L]
  





3array的關(guān)于迭代器的成員函數(shù)

[L]Iterators[/L]


[L]begin  Return iterator to beginning (public member function )[/L]

[L]end          Return iterator to end (public member function )[/L]

[L]rbegin[/B] Return reverseiterator to reverse beginning (public member function )[/L]

[L]rend[/B]         Returnreverse iterator to reverse end (public member function )[/L]

[L]cbegin[/B] Returnconst_iterator to beginning (public member function )[/L]

[L]cend[/B]   Returnconst_iterator to end (public member function )[/L]

[L]crbegin[/B]    Returnconst_reverse_iterator to reverse beginning (public memberfunction )[/L]

[L]crend[/B]  Returnconst_reverse_iterator to reverse end (public member function )[/L]




4array中關(guān)于容量的函數(shù)

[L]Capacity[/L]


[L]size[/B]          Returnsize (public member function )[/L]

[L]max_size[/B]       Returnmaximum size (public member function )[/L]

[L]empty[/B]      Testwhether array is empty (public member function )[/L]


4.1 size()函數(shù)的用法,從結(jié)果中可以看出array容量的一些端倪來(lái)。
size_type size() const;
#include <iostream>
#include <array>
int main ()
{  
std::array<
int,5> myints;
std::cout <<
"size of myints: " << myints.size() << std::endl;

std::cout <<
"sizeof(myints): " <<
sizeof(myints) << std::endl;
return 0;
}結(jié)果
size of myints: 5sizeof(myints): 20
4.2 max_size()函數(shù)的用法,說(shuō)明這個(gè)函數(shù)和list中的max_size()的不同
size_type max_size() const;
#include <iostream>
#include <array>
int main ()
{  
std::array<
int,10> myints;
std::cout <<
"size of myints: " << myints.size() << '\n';

std::cout <<
"max_size of myints: " << myints.max_size() << '\n';
  return 0;
}
結(jié)果:size of myints: 10max_size of myints: 10

4.3 empty函數(shù)

bool empty() const;

5array中關(guān)于元素操作的函數(shù)

[L]Element access[/L]


[L]operator[][/B]     Accesselement (public member function )[/L]

[L]at[/B]             Accesselement (public member function )[/L]

[L]front[/B]        Accessfirst element (public member function )[/L]

[L]back[/B]               Accesslast element (public member function )[/L]

[L]data[/B]               Getpointer to data (public member function )[/L]


5.1 operator[]操作符

reference operator[](size_type off);
const_reference operator[](size_type off) const;
示例:
#include <iostream>
#include <array>
int main ()
{  
  std::array<
int,10> myarray;  
  
unsigned int i;  
  
for (i=0; i<10; i++) myarray=i; // assign some values:  
  
std::cout <<
"myarray contains:";
// print content    
for (i=0; i<10; i++)  
  
std::cout <<
' '<< myarray;

  std::cout <<
'\n';

  
return 0;

}

輸出結(jié)果:

myarray contains: 0 1 2 3 4 5 6 7 8 9

5.2 at()函數(shù)的用法

reference at(size_type off);
const_reference at(size_type off) const;

用法:

#include <iostream>
#include <array>
int main ()
{
std::array<
int,10> myarray;
for (int i=0; i<10; i++)   
    
myarray.at(i) = i+1;
// assign some values:
  std::cout << "myarray contains:" // print content:;
  for (int i=0; i<10; i++)    
    
std::cout <<
' ' << myarray.at(i);

std::cout <<
'\n';
  return 0;
}
輸出結(jié)果:
myarray contains: 1 2 3 4 5 6 7 8 9 10
5.3 front函數(shù)的用法
reference front();
const_reference front() const;
示例:
#include <iostream>
#include <array>
int main ()
{
std::array<
int,3>
myarray = {2, 16, 77};

std::cout <<
"front is: " << myarray.front() << std::endl;  
// 2  
std::cout <<
"back is: " << myarray.back() << std::endl;    
// 77
myarray.front() = 100;

std::cout <<
"myarray now contains:";

for ( int& x : myarray )
std::cout <<
' ' << x;
  std::cout << '\n';
  return 0;
}
結(jié)果:front is: 2back is: 77myarray now contains: 100 16 77
5.4 back函數(shù)的用法reference back();
const_reference back() const;
關(guān)于例子,在5.3中的例子已經(jīng)包含了5.5 data函數(shù)的用法Ty *data();
const Ty *data() const;
返回值指向第一個(gè)元素的指針,因?yàn)槭琼樞虼鎯?chǔ),所以知道了首元素的指針就可以知道所有元素了。
#include <iostream>
#include <cstring>
#include <array>
int main ()
{  
const char* cstr = "Test string";
std::array<
char,12> charray;  
std::memcpy (charray.data(),cstr,12);

std::cout << charray.data() <<
'\n';
  return 0;
}
結(jié)果:Test string6 修改元素的函數(shù)

[L]Modifiers[/L]


[L]fill[/B]      Fill arraywith value (public member function )[/L]

[L]swap[/B]  Swap content (public member function )[/L]


6.1 fill函數(shù)的用法void fill(const Type& _Val);
函數(shù)將array中所有的元素替換成_val
#include <iostream>
#include <array>
int main ()
{

std::array<
int,6> myarray;
  
myarray.fill(5);

std::cout <<
"myarray contains:";

  
for ( int& x : myarray)
{ std::cout <<
' ' << x;
}
  
std::cout <<
'\n';
  
return 0;
}結(jié)果:myarray contains: 5 5 5 5 5 5
6.2 swap函數(shù)的用法void swap(array& right);
交換兩個(gè)具有相同長(zhǎng)度的array,切記兩個(gè)array的長(zhǎng)度必須一致例子:
#include <iostream>
#include <array>
int main ()
{
std::array<
int,5> first = {10, 20, 30, 40, 50};
std::array<
int,5> second = {11, 22, 33, 44, 55};
  
first.swap (second);

  
std::cout <<
"first:";
  for (int& x : first)
std::cout <<
' ' << x;
  std::cout << '\n';
std::cout <<
"second:";

for (int& x : second)
std::cout <<
' ' << x;

std::cout <<
'\n';
  return 0;
}
結(jié)果
first contains: 11 22 33 44 55second contains: 10 20 30 40 50
參考網(wǎng)站:
http://wenku.baidu.com/link?url=fVhoz8y-kXwhcBs1aq0-zcNe8q1lQY8NXFMI7_YWEOGlheZQBYWafojiy36qvnH_7hcrU8kDoBR5VAgnO-wm15nMtvX89C8Hq_1ghp64Cim



    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多