views:

75

answers:

3

I am looking for the code for the c++ string class. What header is it implemented in?

+5  A: 

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

Generally, you are going to be looking for the basic_string template, since std::string is just a specialization of that.

Evan Teran
Thank you. It appears only the prototype of the method I was looking for: find() is in there "size_type find(const _CharT* __s, size_type __pos, size_type __n) const;"
Alan
ahhh sorry. I've found it in basic_string.tcc. Thanks!
Alan
A: 

As you might expect,

<string>

which will most likely be located in whatever include directory your compiler has as its base.

Amber
you are of course right, but keep in mind that (IIRC) `<string>` doesn't actually have to be an actual file. I never seen an implementation where it wasn't though...
Evan Teran
It isn't a file on VMS; header files are contained in 'text libraries', whatever they are. Why, I've no idea.
Brian Hooper
A: 

It's in <string>. It's a header file distributed with your compiler. It may include other (private) header files - a lot of the implementation for Visual Studio is in a file named "xstring".

Terry Mahaffey