for_each


函数原型:
std::for_each
template 
   Function for_each (InputIterator first, InputIterator last, Function fn);

////////////////////////////////////////////////////////////

void myfunction (int i)
{  // function:
  std::cout << ' ' << i;
}
 

void test_my()
{
    std::vector 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';
 

}
/******
运行结果:
myvector contains: 10 20 30

 

你可能感兴趣的:(c++)