for each c++
C++
// for_each example
#include <iostream> // std::cout
#include <algorithm> // std::for_each
#include <vector> // std::vector
void myfunction (int i) { // function:
std::cout << ' ' << i;
}
struct myclass { // function object type:
void operator() (int i) {std::cout << ' ' << i;}
} myobject;
int main () {
std::vector<int> myvector;
myvector.push_back(10);
myvector.push_back(20);
myvector.push_back(30);
std::cout << "myvector contains:";
for_each (myvector.begin(), myvector.end(), myfunction);
std::cout << '\n';
// or:
std::cout << "myvector contains:";
for_each (myvector.begin(), myvector.end(), myobject);
std::cout << '\n';
return 0;
}template<class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function fn)
{
while (first!=last) {
fn (*first);
++first;
}
return fn; // or, since C++11: return move(fn);
}
Also in C++:
- Title
- c++ function to find minimum element in array
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- find vector in c++
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- c++ throw exception
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- registering a new QML type
- Category
- C++
- Title
- reverse in vector c++
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- C++ Student::Student()
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- map insert c++
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++
- Title
- range of int
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- c++ char if
- Category
- C++
- Title
- how to define a while statement in c++
- Category
- C++
- Title
- calling a method on an object c++
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- matrix transpose tiling
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- c++ method name
- Category
- C++
- Title
- iterate through unordered_map c++ in reverse order
- Category
- C++
- Title
- trovare il valore massimo in un array c++ w3
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- restting a queue stl
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- find in string c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- how to get last element of set in c++
- Category
- C++
- Title
- recursive in c++
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- what is meaning of 64 bit integer in c++
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- what is time complexity of min_element()
- Category
- C++
- Title
- pow c++
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- merge sort in c++
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- time conversion hackerrank solution in c++
- Category
- C++
- Title
- matrix eigen c++ example
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- Check if a Number is Odd or Even using Bitwise Operators
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- c++ char to string
- Category
- C++
- Title
- c++ map insert
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- how to use a new node c++
- Category
- C++
- Title
- __builtin_ctz
- Category
- C++
- Title
- centos7 mlock2
- Category
- C++
- Title
- c++ stream string into fiel
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- c++ give options string
- Category
- C++
- Title
- how to import getline in c++
- Category
- C++
- Title
- call by reference c++ example
- Category
- C++
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- c++ formatting
- Category
- C++
- Title
- c++ how to skip the last element of vector
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- c++ not greater than
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- how to get size of 2d vector in c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- find all the palindrome substring in a given string
- Category
- C++
- Title
- double to float c++
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- sort function in vector c++ stl
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- std::substring
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- rand c++
- Category
- C++
- Title
- comparing strings c++
- Category
- C++
- Title
- double max value c++
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- c++ typedef
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- primitive and non primitive data types in c++
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- cin.ignore
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++