What are those _Traits for?
Hi all.
I can see the standard template library has changed a lot since I begun C++
10 years ago...
Now I'm facing with outputing the members of a struct, say Option, which
contains 2 members through ostream. I have defined a vector of Option:
struct Option {
char* name;
int value;
};
typedef vector<Option> ovect;
....
int main()
{
ovect v();
ovect.reserve(10);
...
// Add elements to the vector
cout << v[0];
...
return 0;
}
When I compile (in Bloodshed Dev-C++) I get zillions of errors like:
main.cpp:85: error: no match for 'operator<<' in 'std::operator<< [with
_Traits = std::char_traits<char>](((std::basic_ostream<char,
std::char_traits<char> >&)(+(+std::operator<< [with _CharT = char, _Traits
= std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char>
&)(&std::cout)), std::setw(4)))->std::basic_ostream<_CharT,
_Traits>::operator<< [with _CharT = char, _Traits = std::char_traits<char>
(i))), ((const char*)" ")) << ((const std::vector<gnu_opt,
std::allocator<gnu_opt> >*)(+v))->std::vector<_Tp, _Alloc>::operator[]
[with _Tp = gnu_opt, _Alloc = std::allocator<gnu_opt>](i)'
C:/dev/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/ostream.tcc:63:
note: candidates are: std::basic_ostream<_CharT, _Traits>&
std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT,
_Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>]
....
C:/dev/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/ostream.tcc:74:
note: std::basic_ostream<_CharT, _Traits>&
std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT,
_Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>]
I've digged into the iostream library and I must admit there is nothing like
I used to know about that library before, everything has changed :( .
Especially I can't figure out what the typename _Traits is for in standard
template library templates. I can see _Traits in strings, ostreams,
istreams, aso.
I guess I need to create an operator "<<" for my structure but I have no
idea of what it should look like.
Thanks for any hint/suggestion.
--
Vince C.