Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2084507
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类: C/C++

2008-12-10 15:38:51


vector::begin (STL/CLR)

Designates the beginning of the controlled sequence.

    iterator begin();

The member function returns a random-access iterator that designates the first element of the controlled sequence, or just beyond the end of an empty sequence. You use it to obtain an iterator that designates the current beginning of the controlled sequence, but its status can change if the length of the controlled sequence changes.

// cliext_vector_begin.cpp 
// compile with: /clr
#include

int main()
{
cliext::vector c1;
c1.push_back(L'a');
c1.push_back(L'b');
c1.push_back(L'c');

// display initial contents " a b c"
for each (wchar_t elem in c1)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();

// inspect first two items
cliext::vector::iterator it = c1.begin();
System::Console::WriteLine("*begin() = {0}", *it);
System::Console::WriteLine("*++begin() = {0}", *++it);

// alter first two items and reinspect
*--it = L'x';
*++it = L'y';
for each (wchar_t elem in c1)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
return (0);
}
运行结果
 a b c
*begin() = a
*++begin() = b
x y c
阅读(1000) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~