Deep
Deep

Reputation: 646

Why do we need to use standard library for string but not for int datatype?

In C++, why do we need to use #include <string> standard library to use std::string datatype but we don't need anything like that for int or float datatype?

Upvotes: 1

Views: 788

Answers (1)

Dmitry Kuzminov
Dmitry Kuzminov

Reputation: 6584

C++ is a language and a library. The language takes it's origin in C where int and float are the basic types, so these types are the basics of the language.

The paradigm of C++ is that everything that could be implemented in the library should be implemented there. That means that the language covers the syntax of a class, template, etc, while the actual implementation of std::string is built using these basic language blocks.

To use the library you need to include the appropriate header.

Actually your question is incorrect. Fur sure int and float don't need any headers for historical reasons. But some types like int32_t, intptr_t, uint8_t, etc. are defined in the header .

By the way, the first STL was standartized in 1998: for many years C++ had no common standards for the utilities like containers, string management, etc. That is the reason why multiple third-party libraries exist: every vendor of the compiler had to supply a reasonable library with a bare-bones language.

Upvotes: 1

Related Questions