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];
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];
get last element of stack c++
// stack::top
#include <iostream> // std::cout
#include <stack> // std::stack
int main ()
{
std::stack<int> mystack;
mystack.push(10);
mystack.push(20);
// .top() gets the last/top element of stack c++
mystack.top() -= 5;
std::cout << "mystack.top() is now " << mystack.top() << '\n';
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us