Search code examples
c++templatesiostream

difference between basic_iostream and iostream?


I have done my research before posting this question,and made sure there was not similar questions asked.

I am reading this article http://www.ntu.edu.sg/home/ehchua/programming/cpp/cp10_io.html on streams in C++,and in the diagram in the link I noticed in blue there is basic_iostream and underneath it in green is iostream,the same goes for basic_ifstream and ifstream and so on,

from what I read is that basic_iostream is a template class and iostream is an instantiation of basic_iostream,but what is meant by this?

iostream is not an object like cout,cin and cerr so how is it an instantiation?


Solution

  • In namespace std there's a typedef:

    typedef basic_iostream<char, char_traits<char>> iostream;
    

    That defines iostream as a synonym for basic_iostream<char, char_traits<char>>. When you write something like

    std::iostream my_stream;
    

    you are, in effect, writing

    std::basic_iostream<char, std::char_traits<char>> my_stream.