I am looking for the code for the c++ string class. What header is it implemented in?
The string class is part of the C++ standard library.
std::string class in C++ C++ has in its definition a way to represent a sequence of characters as an object of the class. This class is called std:: string. String class stores the characters as a sequence of bytes with the functionality of allowing access to the single-byte character.
std::string is a typedef for a particular instantiation of the std::basic_string template class. Its definition is found in the <string> header: using string = std::basic_string<char>; Thus string provides basic_string functionality for strings having elements of type char.
@user1145902: They are stored in memory like in an array, but that memory is not allocated in the stack (or wherever the string object is), but rather in a dynamically allocated buffer.
There is no single implementation for std::string
. But you can find your particular implementation in the <string>
header.
On my system it can be found here:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0/include/g++-v4/bits/basic_string.h
and /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0/include/g++-v4/bits/basic_string.tcc
On a Debian-based system:
~$ locate basic_string.tcc
/usr/include/c++/4.5/bits/basic_string.tcc
/usr/include/c++/4.6/bits/basic_string.tcc
~$ locate basic_string.h
/usr/include/c++/4.5/bits/basic_string.h
/usr/include/c++/4.6/bits/basic_string.h
~$
Generally, you are going to be looking for the basic_string
template, since std::string
is just a specialization of that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With