Using the Standard C++ Library in Visual C++ 5.0 |
C++ Library |
Visual C++ 5.0 provides the Standard C++ Library facilities through include files and associated static/dynamic libraries. A C++ program can use the different components of the Standard C++ Library by including the required header and linking with the appropriate static/dynamic library.
NOTE: You cannot mix the old Iostream library and the Standard C++ Library. See the Visual C++ 5.0 Standard C++ Library Frequently Asked Questions for more information.
The following sample creates an array of strings and prints the contents of the array. The array is created using the vector container.
Compile the following program from the command prompt using:
c:\>cl /GX /ML test.cpp
//test.cpp #pragma warning(disable: 4786) #include <vector> #include <string> #include <iostream> int main() { //Create an array of strings std::vector<std::string> Names ; //Create iterator to access elements in the vector std::vector<std::string>::iterator NamesIt ; //Insert elements in the vector Names.push_back("She") ; Names.push_back("sells") ; Names.push_back("sea") ; Names.push_back("shells") ; Names.push_back("by") ; Names.push_back("the") ; Names.push_back("sea") ; Names.push_back("shore") ; std::cout << "Elements in vector Names = " << std::endl ; //print the elements in the vector for(NamesIt = Names.begin(); NamesIt != Names.end(); NamesIt++) { std::cout << *NamesIt << " " ; } std::cout << std::endl ; return 0 ; }
Elements in vector Names = She sells sea shells by the sea shore
The above sample uses three files from the Standard C++ Library. Notice that the header files do not have a ".h" extension. Most of the Standard C++ Library headers do not have the ".h" extension.
The compiler option /ML informs the linker to link this program with LIBC.LIB (Single Threaded C Runtime Library) and LIBCP.LIB (single Threaded Standard C++ Library) in addition to other libraries.
The following section lists the static/dynamic libraries associated with the Standard C++ Library, the Basic C Runtime Library, and the old Iostream Library, and the related compiler options.
NOTE: Starting with Visual C++ 4.2, the Iostream Library was pulled out from C Runtime Library. From Visual C++ 4.2 onwards we have the following libraries in addition to other Visual C++ libraries.
Library types and related compiler switches | Basic C Runtime Library | Standard C++ Library | Old Iostream Library |
Single Threaded (ML) | LIBC.LIB | LIBCP.LIB | LIBCI.LIB |
Multithreaded (MT) | LIBCMT.LIB | LIBCPMT.LIB | LIBCIMT.LIB |
Multithreaded DLL version (MD) | MSVCRT.LIB (Import Library for MSVCRT.DLL) | MSVCPRT.LIB (Also uses MSVCRT.DLL, MSVCP50.DLL) | MSVCIRT.LIB (Import Library for MSVCIRT.DLL) |
Debug Single Threaded (MLd) | LIBCD.LIB | LIBCPD.LIB | LIBCID.LIB |
Debug Multithreaded (MTd) | LIBCMTD.LIB | LIBCPMTD.LIB | LIBCIMTD.LIB |
Debug Multithreaded DLL (MDd) | MSVCRTD.LIB (Import Library for MSVCRTD.DLL) | MSVCPRTD.LIB (Also uses MSVCRTD.DLL, MSVCP50D.DLL) | MSVCIRTD.LIB (Import Library for MSVCIRTD.DLL) |