![]() |
强健的柚子 · 菜鸟怎么快速入门arcgis? - 知乎· 9 月前 · |
![]() |
腹黑的火柴 · 如何在NodeJS中将URL文件转换为Bas ...· 10 月前 · |
![]() |
害羞的鸡蛋面 · 斗罗:重生徐天然,多子多福最新章节全文无弹窗 ...· 12 月前 · |
![]() |
呐喊的乌冬面 · 《快穿系统宿主被灌满的日常临》1-34集超前 ...· 1 年前 · |
![]() |
耍酷的莲藕 · 销售员金口才全书 - 搜狗百科· 1 年前 · |
Vectors are the same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container.
begin() function is used to return an iterator pointing to the first element of the vector container. begin() function returns a bidirectional iterator to the first element of the container.
Syntax :
vectorname.begin() Parameters: No parameters are passed. Return Type: This function returns a bidirectional iterator pointing to the first element.
Examples:
Input : myvector{1, 2, 3, 4, 5}; myvector.begin(); Output : returns an iterator to the element 1 Input : myvector{"This", "is", "Geeksforgeeks"}; myvector.begin(); Output : returns an iterator to the element This
// INTEGER VECTOR EXAMPLE
// CPP program to illustrate
// Implementation of begin() function
#include <iostream>
#include <vector>
using
namespace
std;
int
main()
// declaration of vector container
vector<
int
> myvector{ 1, 2, 3, 4, 5 };
// using begin() to print vector
for
(
auto
it = myvector.begin();
it != myvector.end(); ++it)
cout <<
' '
<< *it;
return
0;
// STRING VECTOR EXAMPLE
// CPP program to illustrate
// Implementation of begin() function
#include <iostream>
#include <string>
#include <vector>
using
namespace
std;
int
main()
// declaration of vector container
vector<string> myvector{
"This"
,
"is"
,
"Geeksforgeeks"
};
// using begin() to print vector
for
(
auto
it = myvector.begin();
it != myvector.end(); ++it)
cout <<
' '
<< *it;
return
0;
end() function is used to return an iterator pointing next to last element of the vector container. end() function returns a bidirectional iterator .
Syntax :
vectorname.end() Parameters : No parameters are passed. Return Type: This function returns a bidirectional iterator pointing to next to last element.
Examples:
Input : myvector{1, 2, 3, 4, 5}; myvector.end(); Output : returns an iterator after 5 Input : myvector{"computer", "science", "portal"}; myvector.end(); Output : returns an iterator after portal
Errors and Exceptions
// using end() to print vector
for
(
auto
it = myvector.begin();
it != myvector.end(); ++it)
cout <<
' '
<< *it;
return
0;
// declaration of vector container
vector<string> myvector{
"computer"
,
"science"
,
"portal"
};
// using end() to print vector
for
(
auto
it = myvector.begin(); it != myvector.end();
++it)
cout <<
' '
<< *it;
return
0;
![]() |
强健的柚子 · 菜鸟怎么快速入门arcgis? - 知乎 9 月前 |
![]() |
腹黑的火柴 · 如何在NodeJS中将URL文件转换为Base64? 10 月前 |
![]() |
耍酷的莲藕 · 销售员金口才全书 - 搜狗百科 1 年前 |