stl vector 函数_vector :: front()函数以及C ++ STL中的示例
stl vector 函數
C ++ vector :: front()函數 (C++ vector::front() function)
vector::front() is a library function of "vector" header, it is used to access the first element from the vector, it returns a reference to the first element of the vector.
vector :: front()是“ vector”頭文件的庫函數,用于訪問向量中的第一個元素,它返回對向量中第一個元素的引用。
Note: To use vector, include <vector> header.
注意:要使用向量,請包含<vector>標頭。
Syntax of vector::front() function
vector :: front()函數的語法
vector::front();Parameter(s): none – It accepts nothing.
參數: 無 –不接受任何內容。
Return value: reference – It returns a reference to the first element of vector.
返回值: reference –返回對向量的第一個元素的引用。
Example:
例:
Input:vector<int> vector1{ 1, 2, 3, 4, 5 };Function call:cout << vector1.front() << endl;Output:1C ++程序演示vector :: front()函數的示例 (C++ program to demonstrate example of vector::front() function)
//C++ STL program to demonstrate example of //vector::front() function#include <iostream> #include <vector> using namespace std;int main() {vector<int> v1{ 10, 20, 30, 40, 50 };//accessing first element//using vector::front() functioncout << "first element is: " << v1.front() << endl;//changing first elementv1.at(0) = 100;cout << "now, first element is: " << v1.front() << endl;return 0; }Output
輸出量
first element is: 10 now, first element is: 100Reference: C++ vector::front()
參考: C ++ vector :: front()
翻譯自: https://www.includehelp.com/stl/vector-front-function-with-example.aspx
stl vector 函數
總結
以上是生活随笔為你收集整理的stl vector 函数_vector :: front()函数以及C ++ STL中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java混合分页_坑,MySQL中 or
- 下一篇: ruby hash方法_Ruby中带有示