简体   繁体   中英

Are the <cstring> header and the <string> header the same?

I'm trying to use the <string> header file but I noticed that there's also the <cstring> header.

What is the difference between the two or are they the same?

Are <cstring> header and string header the same?

No, they are not the same.

what is the difference between them

<cstring> is a C++ standard library header inherited from the C standard library where it's named <string.h> . It declares C standard functions such as std::strlen .

<string> is a C++ standard library header that defines the std::string class (among other things).

The header <string> contains declarations related to the class template std::basic_string .

The header <cstring> refers to declarations in the C Standard header <string.h>

From the C++ 14 Standard (17.6.1.2 Headers)

4 Except as noted in Clauses 18 through 30 and Annex D, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations (7.3.3).

The C declarations from the header <string.h> included in the header <cstring> have C language linkage.

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