+ Reply to Thread
Results 1 to 2 of 2

Thread: How to increase index of stl::list by some value?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    49

    How to increase index of stl::list by some value?

    I am new to sTL and using stl::list.

    How to increase index of stl::list by some value?

    I want to have functionality like stl::vector + operator.

    Help.

  2. #2
    You can use std:advance for this purpose.

    Example:

    Code:
    void UseList()
    {
    	std::list<int> lInts ;
    	for (int nIndex=0; nIndex<10; nIndex++)
    	{
    		lInts.push_back(nIndex) ;
    	}
    	
    	std::list<int>::iterator itr = lInts.begin() ;
    
    	char szMessage[1024] ;
    	sprintf(szMessage, "Value : %d\n", *itr) ;
    	OutputDebugString(szMessage) ;
    	
    	//iterator + 6...
    	itr = lInts.begin() ;
    	std::advance(itr, 6) ;
    
    	sprintf(szMessage, "Value : %d\n", *itr) ;
    	OutputDebugString(szMessage) ;
    	
    }

+ 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