+ Reply to Thread
Results 1 to 2 of 2

Thread: std::copy_if undeclare identifier in C++.

  1. #1

    std::copy_if undeclare identifier in C++.

    Hi All,

    I am getting error:

    std::copy_if undeclare identifier in C++.

    How to solve this?

    Regards

  2. #2
    Hi,

    It is possible that your STL implementation does not support this function.

    Use following method.

    Code:
    #include <vector>
    #include <algorithm>
    
    template<typename In, typename Out, typename Pred>
    Out copy_if(In first, In last, Out res, Pred Pr)
    {
      while (first != last)
      {
        if (Pr(*first))
          *res++ = *first;
        ++first;
      }
      return res;
    }
    
    bool Logic(int nIndex)
    {
    	return (nIndex >= 5) ? true : false ;
    }
    
    void UseCopyIf()
    {
    	std::vector<int> vInts1 ; 
    	for( int nIndex=0; nIndex<10; nIndex++)
    	{
    		vInts1.push_back(nIndex) ;
    	}
    
    	int nArray[10] ;
    	std::fill(&nArray[0], &nArray[10], 0) ;
    	copy_if(vInts1.begin(), vInts1.end(), &nArray[0], Logic) ;
    }

    Hope this will help you.

    Regards.

+ Reply to 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