forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# pop_back | ||
|
||
**Description** : The list::pop_back() function in C++ STL removes the last element in the list container. | ||
|
||
**Example**: | ||
|
||
```cpp | ||
// Demonstrates pop_back() | ||
#include <iostream> | ||
#include <list> | ||
|
||
int main(){ | ||
//declare an empty list | ||
std::list<int> mylist; | ||
|
||
//append elements to the list | ||
mylist.push_back(1); | ||
mylist.push_back(2); | ||
mylist.push_back(3); | ||
|
||
//print list elements | ||
std::cout << "List elements before pop_back()" << std::endl; | ||
for (auto element : mylist) { | ||
std::cout << element << " "; | ||
} | ||
std::cout << std::endl; | ||
|
||
//pop element from the back | ||
mylist.pop_back(); | ||
|
||
//print list elements | ||
std::cout << "List elements after pop_back()" << std::endl; | ||
for (auto element : mylist) { | ||
std::cout << element << " "; | ||
} | ||
|
||
return 0; | ||
} | ||
``` | ||
**[Run Code](https://rextester.com/IBH29509)** |