The information in this article applies to:
SUMMARYThis 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. MORE INFORMATIONStandard C++ Libraries Frequently Asked QuestionsQuestion 1What does the Standard C++ Library contain?A. The Standard C++ Library provides an extensible framework and contains components for language support, diagnostics, general utilities, strings, locales, standard template library (containers, iterators, algorithms, numerics,) and input/output. The Standard C++ Library can be divided into the following categories:
Question 2What is the difference between C-Runtime Library and Standard C++ Library? What libraries will the Runtime Library compiler options such as /ML, /MT, /MD, /MLd, /MTd, and /MDd include?A. Prior to Visual C++ 4.2, the C-Runtime Library included:
Visual C++ 4.2 and later include the following Libraries in addition to
the MFC libraries:
(* 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.)
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.For example, if you specify the /ML (single-thread version) compiler option, and include <iostream>, a Standard C++ Library Header, the libraries LIBC.LIB and LIBCP.LIB are linked with your application by default. If you specify the /ML (single-thread version) compiler option, and include <iostream.h>, an Old iostream Header, the libraries LIBC.LIB and LIBCI.LIB are linked with your application by default. Headers determine whether the Standard C++ Libraries and old iostream Libraries will be linked. Compiler options (/ML[d], /MT[d], /MD[d]) determine which version of the libraries (single-threaded, multithreaded, or DLL) is to be linked by default. NOTE: It may seem that headers without the ".h" extension are Standard C++ Headers and ones with the ".h" extension are C-Runtime Headers or Old iostream Headers. This is not true. As explained below, the files <useoldio.h> and <use_ansi.h> determine the libraries with which your application will link. Actually, there are two header files, <useoldio.h> and <use_ansi.h>, that contain #pragmas. The #pragmas force either the Old iostream Library or the Standard C++ Library to be linked in by default. The header file <useoldio.h> contains #pragma statements that force the Old iostream Library to be linked in. All Old iostream Headers include <useoldio.h>: If you include any Old iostream header in your application, the Old iostream Library will be linked by default.
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.
You cannot mix calls to the Old iostream Library and the new Standard
C++ Library.For more information on related issues, please see Issues Surrounding iostream and the Standard C++ Library in Visual C++ Books Online. Also see Compiler Error C2371. Question 3Can I use existing static or dynamic link libraries, built with Visual C++ 4.0 or Visual C++ 4.1, with applications being developed using Visual C++ 4.2 and later?A. If your application is not going to use the Standard C++ Library, you can use the existing libraries in your application as they exist. If your application is going to use the Standard C++ Library, you need to consider the following issues:
Question 4I ported my application from Visual C++ 4.1 to Visual C++ 4.2 or 5.0. I do not want to use the Standard C++ Libraries. How do I retain the Old iostream functionality?A. If you want to retain the Old iostream Library, include one or more of the Old iostream Header files in your code. Do not use the new Standard C++ Headers. You cannot mix calls to the Old iostream Library and the new Standard C++ Library. For more information, see Issues Surrounding iostream and the Standard C++ Library in Visual C++ Books Online, or Differences between C-Runtime Library and Standard C++ Library? Question 5How do I make the Standard C++ Libraries the default libraries for my application?A. If you want to make the Standard C++ Libraries the default, include one or more of the new Standard C++ headers. Remember, you cannot mix calls to the Old iostream and the new Standard C++ Library. Existing libraries (static or dynamic link) that use iostream functions will have to be rebuilt using Standard C++ Library iostream functions. For more information, see Issues Surrounding iostream and the Standard C++ Library in Visual C++ Books Online, or Differences between C Runtime Library and Standard C++ Library. Question 6Do I still need to include STL in a separate namespace (for example, "std") in order to use it with MFC?A. No. Previous name conflicts between MFC and STL have been resolved in Visual C++ 4.2 and later. The answer is yes if you are using Visual C++ 5.0. NOTE: Visual C++ 4.2 did not implement STL in the namespace "std" but 5.0 and later do. Question 7I want to use Standard C++ Libraries in an MFC application. Will this cause any conflicts with the C-Runtime Libraries?A. No. MFC does not use any C-Runtime functions that will conflict with the Standard C++ Libraries. Question 8I am getting compiler error C2371: 'identifier' redefinition; different basic types. What is causing this?A. Mixing Standard C++ Headers and Old iostream Headers will cause this error, even if they are included in different source files. Following are the different headers:
Question 9I have a project that was built with the "Ignore Default Libraries" Option (/NOD or /NODEFAULTLIB). With Visual C++ 4.2 or later, I am getting linker error LNK2001: unresolved external symbol 'symbol' : on all iostream function calls. What has changed?A. The iostream functions have been removed from the C-Runtime Library. If you are using the Old iostream functions, you will need to add an additional library as follows: LIBCI.LIB (single-threaded <ML>), LIBCIMT.LIB (multithreaded <MT>), or MSVCIRT.LIB (multithreaded dll <MD>). If you are using the New iostream functions included with the Standard C++ Library, you will need to add an additional library as follows: LIBCP.LIB (single-threaded <ML>), LIBCPMT.LIB (multithreaded <MT>), or MSVCPRT.LIB (multithreaded dll <MD>). Do not mix different versions of the libraries. For example, if you are using the single-threaded version of the C-Runtime Library, you must also use the single-threaded version of the Old iostream Library or Standard C++ Library. You cannot mix calls to the Old iostream Library functions and the new Standard C++ Library iostream functions. For more information, see Issues Surrounding iostream and the Standard C++ Library in Visual C++ Books Online. Also see Compiler Error C2371. Question 10I am getting compiler warnings C4786 and/or C4788. None of the symbols in my program is anywhere near 255 characters in length. What is causing this?A. C4786/C4788 is issued when a symbol's name exceeds 255 characters in length. This often happens with templates, and especially STL components. Ignoring this warning is usually safe. Use a #pragma warning (disable: 4786,4788) to suppress the messages. For more information, see Visual C++ Books Online "Build Errors - Compiler Warning (level 1) C4786." Question 11I am getting compiler warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX. What does that mean?A. Programs that use the Standard C++ Library must be compiled with C++ exception handling enabled. C++ exception handling can be enabled by:
- or - Question 12I am getting compiler error C2146, followed by C2065 and finally C2143, all pointing to the same line in my source. What does this mean?A. This sequence of errors can be caused by the following type of construct:
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:
This is consistent with the proposed ANSII specification.
Question 13NOTE: This question does not apply to Visual C++ 5.0 or later.I am getting compiler error C2976 : 'identifier' : too few template parameters, when instantiating STL containers. Why do the Standard Template Library containers of Visual C++ 4.2 require an extra parameter? What is that extra parameter? A. The C++ standard is an evolving piece of work that should provide the most complete and up-to-date implementation of the Standard C++ Library. However, due to certain limitations, some features of the Standard Template Library have been implemented differently. Several STL components use Default Template Arguments. The ANSII draft specification for the STL container classes (such as vector) specifies that the second template argument (the allocator) have a default value of "allocator" as follows:
The pre-defined class allocator utilizes Member Templates. Visual C++
version 4.2 does not support the use of Member Templates.
Because it is not possible to directly implement the class allocator, allocator has been implemented as a template class in the current implementation of the STL. The problem lies in attempting to use the templated allocator class as a default template argument. Consider the following:
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:
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:
This will cause the following compiler error:
To correct the error, the declaration must be changed to:
It is good programming practice to use typedef statements when
instantiating template classes. Using a typedef has the following
advantages:
you can instantiate a template class using the above class template
as follows:
To instantiate in a different source file, you must use:
If the definition of the class template Test changes as follows:
you will have to modify every instance in your source code to reflect
the change.
Using a typedef would have made the process easier because you would only need to change the typedef statement. Use a typedef:
if the class template Test definition changes:
Note that the only necessary change was to the one line containing
the typedef.
This technique of using typedefs will help insulate you from possible future changes to the STL. The vector of ints above, for example, becomes:
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:
REFERENCESFor 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 |
Last Reviewed: July 21, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |