c++ - where is the the c++ string include file?

i'm trying find the C++ string include file. but i only find the string.h file(it's a C strings). can anyone advice me?
It depends on what platform you're on, what compiler/IDE you're using, and where you chose to install it.
the mingw32 compiler with Code Blocks IDE
#include <string> , right click on string → Open #include file → right click on string tab → Open containing folder.

BTW it should be something like \MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++

Here is its content in my MinGw instalation: http://pastebin.com/wq428Nje
Last edited on
"#include <string> , right click on string → Open #include file → right click on string tab → Open containing folder."
"error file not found"... but can compile.. confuse

"BTW it should be something like \MinGW\lib\gcc\x86_64-w64-mingw32\4.8.0\include\c++"
my version don't have the 4.8.0 and c++ folder...
with some dificulty i found the folder, i belive:

C:\Program Files\CodeBlocks\mingw32\lib\gcc\i686-w64-mingw32\4.8.1\include\c++

but the string file(no extension) don't have the 'class string'. so where can i found it?
In one of the files included in that. Probably bits/basic_string.h

Why do you exactly need that? Maybe we can spare you from reading heavely templated code?

BTW string is a typedef for basic_string<char>
Last edited on
finally, i think that i find it.
now i'm add a new function to it... just overloading the operator addition:
1
2
3
4
5
6
basic_string&
      operator+(_CharT strstring1,_CharT strstring2)
      {
	this->push_back((_CharT)strstring1+strstring2);
	return *this;
      }

but i'm getting errors:
" 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator+(_CharT, _CharT)' must take either zero or one argument"

my objective is validate these:
1
2
string b;
        b="hello" + "world";

what i'm doing wrong?
1) For + operator to have 2 argument it must be non-member
2) You cannot overload operators for non-class types only. Isn't going to happen sadly. (Not to mention that adding anything inside standard classes or std namespace is undefined at best)

3) If you are using C++14, use s suffixes: http://coliru.stacked-crooked.com/a/436fffb3f800553d
Last edited on
i use C++ 11 rules.
sorry, can you explain more about the 1) and 2) ?
You know you can use operator+ if you just convert one of the C strings to a std::string?
 
b = string("hello") + "world";
2) Add this to any hello world example and look at the error:
1
2
3
4
int operator+(int, int)
{
    return 0;
}
It pretty much describes everything. To be able to overload operator, at least one operand should not be builtin type. Because of that we have operator+(string, const char*) operator+(const char*, string) overloads, but not operator+(const char*, const char*) Seriously, do you think standard library developers woldn't add this if this was possible?

1) There are two kinds of operators: unary and binary. Unary requires onlt one oprand (like +a, -a, !a, etc.). Binary requires 2 (like a = b, a - b, a % b, etc...).
Operators can be member and non-member. For member operators current class is implicitely first argument of operators, so unary operators require no additional operands, and binary have one.
Peter87: yes i know that... but i'm trying avoid that.
MiiNiPaa: so i can't do that... at least on that way.
Topic archived. No new replies allowed.