Frequently asked questions about the Standard C++ library
This article presents a list of frequently asked questions (FAQs) about the Standard C++ libraries and the answers to those questions.
Original product version: Visual C++
Original KB number: 154419
Question 1: What does Standard C++ library contain
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, and numerics), and input/output.
The Standard C++ library can be divided into the following categories:
Standard Template Library (STL) components provide a C++ program with access to a subset of the most widely used algorithms and data structures. STL headers can be grouped into three major organizing concepts:
Containers: template classes that support common ways to organize data, such as
Algorithms: template functions for performing common operations on sequences of objects, such as functional, algorithm, and numeric.
Iterators: the glue that pastes algorithms and containers together, such as utility, iterator, and memory.
Input/Output includes components for forward declarations of iostreams (
iosfwd), predefined iostreams objects (
iostream), base iostreams classes (
ios), stream buffering (
streambuf), stream formatting and manipulators (
ostream), string streams (
sstream), and file streams (
Other Standard C++ headers include:
Language Support: components for common type definitions used throughout the library (
cstddef), characteristics of the predefined types (
climits), functions supporting start and termination of a C++ program (
cstdlib), support for dynamic memory management (
new), support for dynamic type identification (
typeinfo), support for exception processing (
exception), and other runtime support (
Diagnostics: components for reporting several kinds of exceptional conditions (
stdexcept), documenting program assertions (
cassert), and a global variable for error number codes (
Strings: components for string classes (
string) and null-terminated sequence utilities (
Localization: components that C++ programs may use to encapsulate cultural differences. The locale facility includes internationalization support for character classification and string collation, numeric, monetary, and date/time formatting and parsing, and message retrieval (
Question 2: What is difference between CRT and Standard C++ library? What libraries will Runtime library compiler options include
Visual C++ include the following libraries in addition to the Microsoft Foundation Classes (MFC) libraries:
- Basic C-Runtime library
- Standard C++ library
|Library types and related compiler switches||Basic C Runtime library / Standard C++ library|
|Single-threaded (/ML)||LIBC.LIB / LIBCP.LIB|
|Debug Single-threaded (/MLd)||LIBCD.LIB / LIBCPD.LIB|
|Multithreaded (/MT)||LIBCMT.LIB / LIBCPMT.LIB|
|Debug Multithreaded (/MTd)||LIBCMTD.LIB / LIBCPMTD.LIB|
|Multithreaded DLL (/MD)||MSVCRT.LIB / MSVCPRT.LIB|
|Debug Multithreaded /DLL (MDd)||MSVCRTD.LIB / MSVCPRTD.LIB|
- The /ML and /MLd library compiler options for statically single-threaded libraries have been removed in Visual C++.
- MSVCPRT.lib and MSVCPRTD.lib are static libraries and don't have any dynamic link libraries (DLLs) directly related to them. These libraries are also dependent on MSVCRT.lib and MSVCRTD.lib, 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. Depending on the headers you use in your code, a library from the Standard C++ library may also be linked.
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
|Column 1||Column 2||Column 3||Column 4|
Question 3: How to retain old iostream functionality from Visual C++ .NET 2003 or earlier versions if I port my project from an earlier version
If you want to retain the old
iostream library (iostream.h), include one or more of the old
iostream header files in your code. Don't use the new Standard C++ headers. You can't mix calls to the old
iostream library and the new Standard C++ library.
Question 4: How to make Standard C++ Libraries the default libraries for my application
If you want to make the Standard C++ Libraries the default, include one or more of the new Standard C++ headers. You can't mix calls to the old
iostream and the new Standard C++ library. Existing libraries (static or dynamic link) that use old
iostream functions will have to be modified to use Standard C++ library
Question 5: Will using Standard C++ Libraries in MFC applications cause conflicts with C-Runtime Libraries
No. Microsoft Foundation Classes (MFC) doesn't use any C-Runtime functions that will conflict with the Standard C++ Libraries.
Question 6: Why I get error (error C2065: 'cout' : undeclared identifier) even though I have included iostream
Standard C++ library is implemented in its own namespace
std. Make sure to add the following statement in the beginning of your program:
using namespace std;
Or qualify each Standard C++ library identifier with namespace
std, for example,
Question 7: Why I get error (compiler error C2371: 'identifier' redefinition; different basic types)
In versions of Visual C++ that are earlier than Visual C++ 2005, mixing Standard C++ headers and old
iostream headers causes this error, even if they're included in different source files. The following are the different headers:
Column 1 Column 2 FSTREAM.H IOMANIP.H IOS.H IOSTREAM.H ISTREAM.H OSTREAM.H STDIOSTR.H STREAMB.H STRSTREA.H
Standard C++ headers:
Column 1 Column 2 Column 3 Column 4 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
Question 8: Why I get message (LNK2001: unresolved external symbol 'symbol';) on iostream function calls when the project is built with Ignore Default Libraries
iostream functions have been removed from the C-Runtime library.
If you're using the old
iostream functions, you must add an additional library LIBCI.lib (single-threaded ML), LIBCIMT.lib (multithreaded MT), or MSVCIRT.lib (multithreaded dll MD). These libraries have been removed from Visual C++.
If you're using the new
iostream functions included with the Standard C++ library, you must add an additional library LIBCP.lib (single-threaded ML), LIBCPMT.lib (multithreaded MT), or MSVCPRT.lib (multithreaded dll MD).
Don't mix different versions of the libraries. For example, if you're 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 can't mix calls to the old
iostream library functions and the new Standard C++ library
Question 9: Why do I get compiler warnings C4786 or C4788? None of the symbols in my program is anywhere near 255 characters in length
C4786 or C4788 is issued when a symbol's name exceeds 255 characters in length. This often happens with template class, and
STL uses template class extensively.
Ignoring this warning is safe. Use a
#pragma warning (disable: 4786,4788) to suppress the messages.
Question 10: Why I get message (C4530: C++ exception handler used, but unwind semantics aren't enabled. Specify -GX)
Programs that use the Standard C++ library must be compiled with C++ exception handling enabled. C++ exception handling can be enabled by one of the following methods:
- Selecting the Enable exception handling option in the C++ Language Category of the C/C++ tab in the Project Settings dialog box.
- Using the /GX compiler switch.
Question 11: Why I get compiler error C2146, followed by C2065, and finally C2143, all pointing to the same line in my source
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 construct becomes:
vector<int, allocator<int> > iV;
This is consistent with the proposed ANSII specification.