FAQ: Standard C++ Library Frequently Asked QuestionsID: Q154419
|
This article presents a list of Frequently Asked Questions (FAQs) regarding the Standard C++ Libraries, and the answers to those questions. For additional information regarding the Standard C++ Libraries, please refer to the draft ANSII Standard Specification and the Visual C++ Books Online.
|------------------------------------------------------------|
| C-Runtime Library Types and | Standard C++ |
| Related Compiler Switches | Library |
| -----------------------------------------------------------|
| Single Threaded (ML) | LIBC.LIB |
| Multithreaded (MT) | LIBCMT.LIB |
| Multithreaded DLL version (MD) | MSVCRT.LIB (Import |
| | Library for |
| | MSVCRT40.DLL) |
| Debug Single Threaded (MLd) | LIBCD.LIB |
| Debug Multithreaded (MTd) | LIBCMTD.LIB |
| Debug Multithreaded DLL (MDd) | MSVCRTD.LIB (Import |
| | Library for |
| | MSVCRT40D.DLL) |
|------------------------------------------------------------|
Visual C++ 4.2 and later include the following Libraries in addition to
the MFC libraries:
|--------------------------------|---------------------------|
| Library Types and | Basic C Runtime |
| Related Compiler Switches | Library |
|--------------------------------|---------------------------|
| Single-Threaded (ML) | LIBC.LIB |
| Multithreaded (MT) | LIBCMT.LIB |
| Multithreaded DLL version (MD) | MSVCRT.LIB (Import |
| | Library for |
| | MSVCRT.DLL) |
| Debug Single-Threaded (MLd) | LIBCD.LIB |
| Debug Multithreaded (MTd) | LIBCMTD.LIB |
| Debug Multithreaded DLL (MDd) | MSVCRTD.LIB (Import |
| | Library for |
| | MSVCRTD.DLL) |
|------------------------------------------------------------|
|--------------------------------|---------------------------|
| Library Types and | Standard C++ |
| Related Compiler Switches | Library |
|--------------------------------|---------------------------|
| Single-Threaded (ML) | LIBCP.LIB |
| Multithreaded (MT) | LIBCPMT.LIB |
| Multithreaded DLL version (MD) | MSVCPRT.LIB*(Also uses |
| | MSVCRT.DLL) |
| Debug Single-Threaded (MLd) | LIBCPD.LIB |
| Debug Multithreaded (MTd) | LIBCPMTD.LIB |
| Debug Multithreaded DLL (MDd) | MSVCPRTD.LIB* (Also |
| | uses MSVCRTD.DLL) |
|------------------------------------------------------------|
(* NOTE: MSVCPRT.LIB and MSVCPRTD.LIB are static libraries and do not
have any DLLs directly related to them. These libraries are also
dependent on MSVCRT.DLL and MSVCRTD.DLL, respectively. If you have any
applications that use MSVCPRT.LIB or MSVCPRTD.LIB and you use the
"Ignore Default Library" (/NOD or NODEFAULTLIB) option, be sure to link
MSVCPRT.LIB (or MSVCPRTD.LIB) and MSVCRT.LIB (or MSVCRTD.LIB) with your
application. Otherwise, you will get linker errors (LNK2001: unresolved
externals in MSVCPRT.LIB or MSVCPRTD.LIB) when linking your
application.)
|--------------------------------|---------------------------|
| Library Types and | Old iostream |
| Related Compiler Switches | Library |
|--------------------------------|---------------------------|
| Single-Threaded (ML) | LIBCI.LIB |
| Multithreaded (MT) | LIBCIMT.LIB |
| Multithreaded DLL version (MD) | MSVCIRT.LIB (Import |
| | Library for |
| | MSVCIRT.DLL) |
| Debug Single-Threaded (MLd) | LIBCID.LIB |
| Debug Multithreaded (MTd) | LIBCIMTD.LIB |
| Debug Multithreaded DLL (MDd) | MSVCIRTD.LIB (Import |
| | Library for |
| | MSVCIRTD.DLL) |
|------------------------------------------------------------|
In Visual C++ 4.2 and later, there are certain default libraries that your
program will link with. When you build a release version of your project
in Visual C++ 4.2 and later, one of the basic C-Runtime Libraries
(LIBC.LIB, LIBCMT.LIB, and MSVCRT.LIB) is linked by default, depending
on the compiler option you choose (single-threaded <ML[d]>,
multithreaded <MT[d]>, or DLL<ML[d]>). Depending on the headers you use
in your code, a library from the Standard C++ Library or one from the
Old iostream Library may also be linked.
|-------------------------|
| Old iostream Headers |
|-------------------------|
| |
| FSTREAM.H | IOMANIP.H |
| IOS.H | IOSTREAM.H |
| ISTREAM.H | OSTREAM.H |
| STDIOSTR.H | STREAMB.H |
| STRSTREA.H | |
|-------------------------|
The header file <use_ansi.h> contains #pragma statements that force the
Standard C++ Library to be linked in. All Standard C++ headers include
<use_ansi.h>: if you include any Standard C++ Header in your
application, the Standard C++ Library will be linked by default.
|-------------------------------------------------|
| Standard C++ Headers |
|-------------------------------------------------|
| ALGORITHM | BITSET | COMPLEX | DEQUE |
| EXCEPTION | FSTREAM | FUNCTIONAL | IOMANIP |
| IOS | IOSFWD | IOSTREAM | ISTREAM |
| ITERATOR | LIMITS | LIST | LOCALE |
| MAP | MEMORY | NUMERIC | OSTREAM |
| QUEUE | SET | SSTREAM | STACK |
| STDEXCEPT | STREAMBUF | STRING | STRSTREAM |
| TYPEINFO | UTILITY | VALARRAY | VECTOR |
|-------------------------------------------------|
You cannot mix calls to the Old iostream Library and the new Standard
C++ Library.
|-------------------------|
| Old iostream Headers |
|-------------------------|
| FSTREAM.H | IOMANIP.H |
| IOS.H | IOSTREAM.H |
| ISTREAM.H | OSTREAM.H |
| STDIOSTR.H | STREAMB.H |
| STRSTREA.H | |
|-------------------------|
|-------------------------------------------------|
| Standard C++ Headers |
|-------------------------------------------------|
| ALGORITHM | BITSET | COMPLEX | DEQUE |
| EXCEPTION | FSTREAM | FUNCTIONAL | IOMANIP |
| IOS | IOSFWD | IOSTREAM | ISTREAM |
| ITERATOR | LIMITS | LIST | LOCALE |
| MAP | MEMORY | NUMERIC | OSTREAM |
| QUEUE | SET | SSTREAM | STACK |
| STDEXCEPT | STREAMBUF | STRING | STRSTREAM |
| TYPEINFO | UTILITY | VALARRAY | VECTOR |
|-------------------------------------------------|
vector<int, allocator<int>>iV;
The problem is caused by the consecutive >> at the end of the
declaration. The solution is to put a space between two characters, so
the above construct becomes:
vector<int, allocator<int> > iV;
This is consistent with the proposed ANSII specification.
template<class T, class Allocator = allocator> class vector;
The pre-defined class allocator utilizes Member Templates. Visual C++
version 4.2 does not support the use of Member Templates.
template<class T, class Allocator = allocator<T> > class vector;
Visual C++ 4.2 does not support this syntax. This made it necessary, in
the case of STL containers, to remove the default template argument for
the allocator. The definition of vector now becomes:
template<class T, class Allocator> class vector;
The effect of this change is that declaring a container will now
require that you explicitly specify the allocator class as a template
argument. The following declaration of an int vector illustrates:
vector<int> myVector;
This will cause the following compiler error:
To correct the error, the declaration must be changed to:Compiler error C2976 : 'vector' : too few template parameters
vector<int, allocator<int> > myVector;
It is good programming practice to use typedef statements when
instantiating template classes. Using a typedef has the following
advantages:
template <class A, class B, class C, class D>
class Test
{
} ;
you can instantiate a template class using the above class template
as follows:
Test<int, int, float, float> ifClass1 ;
To instantiate in a different source file, you must use:
Test<int, int, float, float> ifClass2 ;
If the definition of the class template Test changes as follows:
template <class A, class B, class C, class D, class E>
class Test
{
} ;
you will have to modify every instance in your source code to reflect
the change.
template <class A, class B, class C, class D>
class Test
{
} ;
typedef Test<int, int, float, float > MYCLASS ;
MYCLASS myObj1 ;
MYCLASS myObj2 ;
if the class template Test definition changes:
template <class A, class B, class C, class D, class E>
class Test
{
} ;
typedef Test<int, int, float, float, char> MYCLASS ;
MYCLASS myObj1 ;
MYCLASS myObj2 ;
Note that the only necessary change was to the one line containing
the typedef.
typedef vector<int, allocator<int> > INTVECTOR;
If all instances of a vector of ints are declared as type INTVECTOR, you
will only need to change the typedef if a future version of Visual C++
returns to using a default template argument of allocator. Typedefs used
in conjunction with conditional compilation can also help those dealing
with multiple platform situations using multiple versions of STL. For
example, a program being compiled for both UNIX (using HP's STL)
and NT (using Visual C++ 4.2's STL) might have the following definition
of INTVECTOR:
#ifdef _MSC_VER // VC++ STL
typedef vector<int, allocator<int> > INTVECTOR;
#else // HP STL
typedef vector<int> INTVECTOR;
#endif
For latest technical discussions concerning the Standard C++ Library see Microsoft Frequently Asked Questions in the Microsoft Technical Support Web site at http://www.microsoft.com/visualc/stl/.
Additional query words: STL STL.H allocator vector deque list map multimap set multiset queue stack priority_queue
Keywords : kbVC420 kbVC500 kbVC600 STLIss
Version : winnt:4.2,5.0,6.0
Platform : winnt
Issue type :
Last Reviewed: July 20, 1999