libstdc++: compiling with iostream header: error: unknown type name 'char_traits'

Nobin Mathew
Sun Jun 20 13:43:00 GMT 2010


I am having a problem with libstdc++ headers, I am having a simple
application which uses iostream library. In order to parse it I am
using clang library application.

For that I am getting an error like this

In file included from /home/nmathew/Desktop/algorithms/array.cpp:1:
In file included from /usr/include/c++/4.4.3/iostream:39:
In file included from /usr/include/c++/4.4.3/ostream:39:
In file included from /usr/include/c++/4.4.3/ios:38:
In file included from /usr/include/c++/4.4.3/iosfwd:40:
/usr/include/c++/4.4.3/bits/stringfwd.h:49:48: error: unknown type
name 'char_traits'

If I use g++ it compiles properly.

My include search directories are   below:

#include "..." search starts here:
#include <...> search starts here:
End of search list.

When I looked at the header source, this is the order of inclusion

iosfwd uses uses char_traits but bits/char_traits.h is included after
iosfwd in ios header

>From /usr/include/c++/4.4.3/ios

#ifndef _GLIBCXX_IOS
#define _GLIBCXX_IOS 1

#pragma GCC system_header

#include <iosfwd>
#include <exception>            // For ios_base::failure
#include <bits/char_traits.h>   // For char_traits, streamoff, streamsize, fpos
#include <bits/localefwd.h>     // For class locale
#include <bits/ios_base.h>      // For ios_base declarations.
#include <streambuf>
#include <bits/basic_ios.h>

#endif  /* _GLIBCXX_IOS */

>From /usr/include/c++/4.4.3/iosfwd



#pragma GCC system_header

#include <bits/c++config.h>
#include <bits/stringfwd.h>     // For string forward declarations.
#include <bits/postypes.h>


  template<typename _CharT, typename _Traits = char_traits<_CharT> >
    class basic_ios;

  template<typename _CharT, typename _Traits = char_traits<_CharT> >
    class basic_streambuf;

How this works and what is the use of bits/c++config.h file.

Please help even if this is a dump question, I am new to the land of c++.


More information about the Gcc-help mailing list