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++ access second last element of vector

arr2.rbegin()[1] // rbegin() is reverse order starting at 0 for last element, 1 for second-last
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 :: how to create a file in c++ 
Cpp :: how to use a non const function from a const function 
Cpp :: why convert char* to string c++ 
Cpp :: C++ String Compare Example 
Cpp :: map count function c++ 
Cpp :: Nested if...else 
Cpp :: grep xargs sed 
Cpp :: accumulate vector c++ 
Cpp :: c++ math 
Cpp :: variables in c++ 
Cpp :: C++ sum a vector of digits 
Cpp :: selection sort c++ 
Cpp :: how to take full sentence in c++ 
Cpp :: long long int range c++ 
Cpp :: create new node in tree 
Cpp :: cpp oop 
Cpp :: power in c++ 
Cpp :: find the graph is minimal spanig tree or not 
Cpp :: c++ while loop 
Cpp :: c++ program to convert fahrenheit to celsius 
Cpp :: c ++ program to insert into hashmap 
Cpp :: c++ write to file in directory 
Cpp :: what is the time complexitry of std::sort 
Cpp :: minimum characters to make string palindrome 
Cpp :: Basic Makefile C++ 
Cpp :: A Program to check if strings are rotations of each other or not 
Cpp :: binary tree 
Cpp :: map of maps c++ 
Cpp :: java to puthon converter 
Cpp :: 41.00 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =