Command Line.
Assume a C++ program named vector.cpp:
#define __MINMAX_DEFINED // use STL's generic min and max templates #define __USE_STL // exclude BC++'s redundant operator definitions // STL include files - include STL files first! #include "vector.h" // C++ standard include files #include <stdlib.h> // stdlib min and max functions are skipped #include <cstring.h> // only compilable with __USE_STL directive #include <classlib\alloctr.h> // only compilable with __USE_STL directive #include <iostream.h> void main (void) { vector<int> v(5); v[0] = 4; cout << "First vector element: " << v[0]; }
I recommend to include all STL include files before the Borland C++ standard include files, although this causes some work to be done.
There are some changes to be made in the include files <bc4\include\cstring.h> and <bc4\include\classlib\alloctr.h>, if you plan to use them. Some operator definitions have to be taken out of compilation, for example by adding
#if !defined (__USE_STL) [...] #endif,
because STL generates these operators automatically using template operator definitions.
The code after adding the necessary #if directives (italic letters) is shown in the following box. The line numbers indicate the operator-definition-positions in the original include files:
line 724: #if !defined(__USE_STL) inline int _RTLENTRY operator != ( const string _FAR &s1, const string _FAR &s2 ) THROW_NONE { [...] } #endif line 850: #if !defined(__USE_STL) inline int _RTLENTRY operator <= ( const string _FAR &s1, const string _FAR &s2 ) THROW_NONE { [...] } #endif line 866: #if !defined(__USE_STL) inline int _RTLENTRY operator > ( const string _FAR &s1, const string _FAR &s2 ) THROW_NONE { [...] } #endif line 882: #if !defined(__USE_STL) inline int _RTLENTRY operator >= ( const string _FAR &s1, const string _FAR &s2 ) THROW_NONE { [...] } #endif
<bc4\include\classlib\alloctr.h>, line 44:
#if !defined(__USE_STL) friend void *operator new( unsigned, void *ptr ) { return ptr; } #endif
Compile and link .cpp files using STL with the following command:
bcc -I<path-to-stl-directory> <file>.cpp
Example:
bcc -Ic:\bc4\stl vector.cppIt is also possible to include the STL include files after the Borland C++ standard include files, then programs would even compile without having changes in <bc4\include\cstring.h>. But STL provides a number of template functions that increase genericity and template operator definitions that generate operator!= out of operator== and operators >, >=, <= out of operator<, so it seems advisable to choose the practice shown above.
Create a project specifying "DOS-Standard" as target-platform. Specify the STL-directory under "options/project/directories" (german: "Optionen/Projekt/Verzeichnisse") as include-directory. Use the #define __MINMAX_DEFINED statement when <stdlib.h> is included, use #define __USE_STL when <cstring.h> and <classlib\alloctr.h> are included.