+ Reply to Thread
Results 1 to 2 of 2

Thread: What is difference between vector size and capcity?

  1. #1

    What is difference between vector size and capcity?

    What is difference between vector size and capcity?

  2. #2
    Example:

    Code:
    UseVector()
    {
            std::vector<int> vInts ;
    	vInts.push_back(1) ;
    	vInts.push_back(2) ;
    	vInts.push_back(3) ;
    
    	size_t size	= vInts.size() ;
    	size_t capacity = vInts.capacity() ;
    	size_t max_capacity = vInts.max_size() ;
    
    	char szMessage[100] ;
    	sprintf(szMessage, "size is = %d", size) ;
    	sprintf(szMessage, "capcity is = %d", capacity) ;
    	sprintf(szMessage, "max-capcity is = %d", max_capacity) ;
    }
    a. vector::size - Returns number of elements in the vector.
    b. vector::capacity - Returns number of elements for which memory has been allocated.
    c. vector::max_size - Returns maximum number of elements vector could hold.

+ 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