简体   繁体   中英

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

在 C++ 中,为什么我们需要使用#include <string>标准库来使用std::string数据类型,而对于intfloat数据类型我们不需要类似的东西?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM