+ Reply to Thread
Results 1 to 2 of 2

Thread: How to copy reverse items from the vector in to other vector?

  1. #1

    How to copy reverse items from the vector in to other vector?

    Hi All,

    How to copy reverse items from the vector in to other vector?

    Thanks

  2. #2
    You can use std::reverse_copy.

    Example:

    Code:
    void UseReverseCopy()
    {
    	std::vector<int> aInts1 ;
    	for (int nIndex=0; nIndex<10; nIndex++)
    	{
    		aInts1.push_back(nIndex) ;
    	}
    
    	std::vector<int> aInts2 ;
    	
    	aInts2.resize(aInts1.size()) ;
    	
    	std::reverse_copy(aInts1.begin(), aInts1.end(), aInts2.begin()) ;
    
    	char szMessage[1024] ;
    
    	std::vector<int>::const_iterator itr = aInts2.begin() ;
    	for(; itr != aInts2.end(); itr++)
    	{
    		sprintf(szMessage, "Value : %d\n", *itr) ;
    		OutputDebugString(szMessage) ;
    	}
    }
    Hope this helps.

+ 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