This non-standard header can be used to forward declare basic_string (much like <iosfwd> forward declares streams). There is also a <stringfwd.h> that forward declares basic_string and places it into the global namespace.
namespace std { // Optional template <class T> class allocator; template<class charT> struct char_traits; template <class charT, class traits, class Allocator> class basic_string; typedef basic_string <char, char_traits<char>, allocator<char> > string; typedef basic_string <wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring; }
Including <stringfwd> allows you to use a string object.
#include <stringfwd> class MyClass { .... std::string* my_string_ptr; };
The headers <stringfwd.h> and <string> can be used in combination to place string into the global namespace, much like is done with other <name.h> headers. The header <string.h> does not work because that is a standard C header.
#include <stringfwd.h> #include <string> int main() { string a("Hi"); // no std:: required return 0; }