Search
 
SCRIPT & CODE EXAMPLE
 

CPP

access last element in vector in c++

vector<int> v;
cout << v[v.size() - 1];
cout << *(v.end() - 1);
cout << *v.rbegin();
// all three of them work
Comment

cpp get last element of vector

vector<int> vec;
vec.push_back(0);
vec.push_back(1);
int last_element = vec.back();
int also_last_element = vec[vec.size() - 1];
Comment

c++ get last element in vector

std::v.back()
Comment

c++ last element of vector

int var = vec.back().c;
Comment

PREVIOUS NEXT
Code Example
Cpp :: operator overloading c++ 
Cpp :: c++ itoa 
Cpp :: max and min function in c++ 
Cpp :: error in c++ 
Cpp :: Write a C++ program using constructor 
Cpp :: linkedlist in c++ 
Cpp :: map of maps c++ 
Cpp :: Check whether the jth object is in the subset 
Cpp :: C/C++ loop for 
Cpp :: pthread c++ example with output 
Cpp :: C++ file . 
Cpp :: heapsort 
Cpp :: end vs cend in cpp 
Cpp :: how to read rotary encoder c++ 
Cpp :: convert hex to decimal arduino 
Cpp :: cplusplusbtutotrail 
Cpp :: prompt user for bool statement C++ 
Cpp :: true false operator 
Cpp :: std::is_standard_layout 
Cpp :: cout alternative c++ 
Cpp :: c++ over load oprator to print variable of clas 
Cpp :: ue4 c++ enum variable declaration 
Cpp :: how to print out a two dimensional array in c++ 
Cpp :: c++ system() from variable 
Cpp :: C++ meaning :: 
Cpp :: statement that causes a function to end in c++ 
Cpp :: For auto map C 
Cpp :: fast scan in c++ 
Cpp :: find the mminimum of the vector and its position in c++ 
Cpp :: rand() and srand() in C/C++ 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =