+ Reply to Thread
Results 1 to 2 of 2

Thread: How to pass stl vector in c language function?

  1. #1

    How to pass stl vector in c language function?

    How to pass stl vector in c language function?

  2. #2
    Following is the example:

    Code:
    //your header file, UseVector.h
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    	void UseVector(int aArray[10], int nItems) ;
    
    
    #ifdef __cplusplus
    }
    #endif
    
    
    //your source file, UseVector.c, this is "c" source file
    #include "UseVector.h"
    #include <stdio.h>
    
    void UseVector(int aArray[10], int nItems)
    {
    	int nIndex ;
    	char szMesage[100] ;
    	for (nIndex=0; nIndex<nItems; nIndex++)
    	{
    		sprintf(szMesage, "Number = %d", aArray[nIndex]) ;
    	}
    }
    
    //your cpp source file, UseVector.cpp
    void UseSTLVector()
    {
            std::vector<int> vInts ;
    	vInts.push_back(1) ;
    	vInts.push_back(2) ;
    	vInts.push_back(3) ;
    
    	UseVector(&vInts[0], vInts.size()) ;
    }

+ 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