- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
2K+ Views
Here we will see how to sort an array using STL functions in C++. So if the array is like A = [52, 14, 85, 63, 99, 54, 21], then the output will be [14 21 52 54 63 85 99]. To sort we have one function called sort() present in the header file . The code is like below −Example Live Demo#include #include using namespace std; int main() { int arr[] = {52, 14, 85, 63, 99, 54, 21}; int n = sizeof(arr) / sizeof(arr[0]); cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
780 Views
Here we will see how to reverse an array using STL functions in C++. So if the array is like A = [10, 20, 30, 40, 50, 60], then the output will be B = [60, 50, 40, 30, 20, 10]. To reverse we have one function called reverse() present in the header file . The code is like below −Example Live Demo#include #include using namespace std; int main() { int arr[] = {10, 20, 30, 40, 50, 60}; int n = sizeof(arr) / sizeof(arr[0]); cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
419 Views
Suppose we have one STL list in C++. There are few elements. We have to insert a new element into the list. We can insert at the end, or beginning or at any position. Let us see one code to get better understanding. To insert at beginning we will use push_front(), To insert at end, we will use push_end() and to insert at any position, we have to use some operations. we have to initialize one iterator, then move that iterator to correct position, then insert into that place using insert() method.Example Live Demo#include #include using namespace std; void display(list my_list){ ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
273 Views
Here we will see how to find the sum of all element of an array. So if the array is like [12, 45, 74, 32, 66, 96, 21, 32, 27], then sum will be: 405. So here we have to use the accumulate() function to solve this problem. This function description is present inside header file.Example Live Demo#include #include using namespace std; int main() { int arr[] = {12, 45, 74, 32, 66, 96, 21, 32, 27}; int n = sizeof(arr) / sizeof(arr[0]); cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
1K+ Views
Here we will see how to find the maximum and minimum element from an array. So if the array is like [12, 45, 74, 32, 66, 96, 21, 32, 27], then max element is 96, and min element is 12. We can use the max_element() function and min_element() function, present in algorithm.h header file to get the maximum and minimum elements respectively.Example Live Demo#include #include using namespace std; int main() { int arr[] = {12, 45, 74, 32, 66, 96, 21, 32, 27}; int n = sizeof(arr) / sizeof(arr[0]); cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
3K+ Views
Here we will see how to find the maximum element. So if the array is like [12, 45, 74, 32, 66, 96, 21, 32, 27], then max element is 96. We can use the max_element() function present in algorithm.h header file to get the maximum element.Example Live Demo#include #include using namespace std; int main() { int arr[] = {12, 45, 74, 32, 66, 96, 21, 32, 27}; int n = sizeof(arr) / sizeof(arr[0]); cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
785 Views
Suppose we have one STL set in C++. There are few elements. We have to delete the last element from that set. So if the elements are like [10, 41, 54, 20, 23, 69, 84, 75], then the set will be like [10 20 23 41 54 69 75 84], and last element is 84. We will see the C++ code to delete last element from set.Example Live Demo#include #include using namespace std; void display(set my_set){ for (auto it = my_set.begin(); it != my_set.end(); ++it) cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
470 Views
Here we will see how to delete the last element from C++ STL map. The map is the hash table based data type, it has key and value. We can use the prev() method to get last element, and erase() function to delete as follows.Example Live Demo#include #include using namespace std; int main() { map my_map; my_map["first"] = 10; my_map["second"] = 20; my_map["third"] = 30; cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
461 Views
Suppose we have one STL list in C++. There are few elements. We have to delete the last element from that list. So if the elements are like [10, 41, 54, 20, 23, 69, 84, 75], then last element is 75. We will see the C++ code to delete last element from list.Example Live Demo#include #include using namespace std; void display(list my_list){ for (auto it = my_list.begin(); it != my_list.end(); ++it) cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
382 Views
Here we will see how to delete one element from set by passing the value as argument. So if the set is like {10, 20, 30, 50, 60, 80, 90, 100, 120, 200, 500}, and we want to delete 90, it will be: {10, 20, 30, 50, 60, 80, 100, 120, 200, 500}In set each element can occur only once and they are arranged. The value of the element cannot be modified when it is added, so this is immutable. Though we can add or remove elements from it.We can use the erase() method to do this task.Example Live Demo#include #include ... Read More