Vector Elements using for_each() Algorithm in C++

This C++ program prints the elements of vector using for_each() algorithm. The program creates a vector, instantiates the value of elements using assign member function and prints the vector elements using for_each algorithm. The for_each function uses a predicate to print element by element as the iterator goes through the vector. Here is the source … Read more

advertisement

Map Elements using for_each Algorithm in C++

This C++ program prints elements of map using for_each algorithm. The for_each function takes three parameters – iterator to the beginning of the container, the iterator to the end of the container and a function or function object of class X. A function object is a programming construct allowing an object to be invoked or … Read more

advertisement

Vector Addition using for_each() Algorithm in C++

This C++ program computes the sum of integer elements of vector using for_each algorithm. The algorithm uses an auxiliary function object. The data member sum is initialized to zero and the operator is called with every integer element of the vector which is added to the data member. The value of the sum is printed. … Read more

advertisement

Bidirectional Iterators in C++

This C++ program demonstrates the use of bidirectional iterator on vector container. A bidirectional iterator is one which can sequentially iterate through a container in both the directions. C++ provides two such non-const iterators – reverse_iterator and iterator. Here is the source code of the C++ program demonstrates bidirectional iterator on vector container. The C++ … Read more

advertisement

C++ Program to Demonstrate Splice Operation on Lists

This C++ program demonstrates the splice operation on std::list container. The splice operation removes the elements from one std::list and copies them into another. The program uses two versions of std::list::splice – one which moves only the element pointed by an iterator and second which moves the elements between the beginning and ending iterators. Here … Read more

advertisement

size() and resize() Functions in C++

This C++ program demonstrates size() and resize() functions on a vector. The function size() returns the size of the container and the function resize() resizes the container to the specified size and moves the elements to the new allocated space. Here is the source code of the C++ program which demonstrates size() and resize() functions … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.