WIN_C++_Vector

// -------------------------------------------------------
// windows c++ vector define start
#include <vector>

typedef struct{
  int  id;
  char* name;
} MY_DATA;

typedef std::vector< MY_DATA > MY_VECTOR;

MY_VECTOR my_vector;
// windows c++ vector define end
// -------------------------------------------------------

// -------------------------------------------------------
// windows c++ add member to vector start
char strName[NAME_MAX_SIZE];
sprintf( strName, "%s", "your name message.");

MY_DATA item;
item.name = new char[NAME_MAX_SIZE];
::memset( item.name, NULL, NAME_MAX_SIZE );
item.id = 100;
lstrcpy( item.name, strName );
my_vector.push_back( item );
// windows c++ add member to vector end
// -------------------------------------------------------

// -------------------------------------------------------
// windows c++ delete member from vector start
MY_VECTOR::iterator pos = my_vector.begin();
for ( ; pos != my_vector.end() ; ++pos ) {
  if ( 100 == (*pos).id ) {
    free( (*pos).name );
    (*pos).name = NULL ;
    my_vector.erase( pos );
    break;
  }
}
// windows c++ delete member from vector end
// -------------------------------------------------------

// -------------------------------------------------------
// windows c++ search member from vector start
char* getName = new char[ NAME_MAX_SIZE ];
::memset( getName, NULL, NAME_MAX_SIZE );
MY_VECTOR::iterator pos = my_vector.begin();
for ( ; pos != my_vector.end() ; ++pos ) {
  if ( 100 == (*pos).id ) {
    lstrcpy( getName, (*pos).name );
    break;
  }
}
// add your code here.
// -------------------
// add your code here.
free( getName );
getName = NULL;
// windows c++ search member from vector end
// -------------------------------------------------------

cl /c /GX -IC:\j2sdk1.4.2_11\include -IC:\j2sdk1.4.2_11\include/win32 XXX.cpp
link /OUT:XXX.dll /NOLOGO /DLL XXX.obj kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
odbccp32.lib LIBCMT.lib /NODEFAULTLIB:LIBC.LIB

0 コメント: