+ Reply to Thread
Results 1 to 2 of 2

Thread: Using labmda in STL algorithm function

  1. #1

    Using labmda in STL algorithm function

    I want to learn how can I pass a lambda in STL algorithm function like std::for_each or std::find. Please provide some simple example.

  2. #2
    Follow the below simple example:

    Code:
    void LambdaWithSTLAlgorithm()
    {
    	std::vector<int> myVector ;
    
    	myVector.push_back(10) ;
    	myVector.push_back(20) ;
    	myVector.push_back(30) ;
    	myVector.push_back(40) ;
    	myVector.push_back(50) ;
    
    	std::for_each(myVector.begin(), myVector.end(), [] (int n)
    														{
    															CString strMessage ;
    															strMessage.Format("Value is : %d", n) ;
    															OutputDebugString(strMessage.GetBuffer(0)) ;
    														}) ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts