Is it OK to use iostreams with int as character-type?

后端 未结 2 1619
暖寄归人
暖寄归人 2021-01-02 17:05

When trying to come up with an answer to this question, I wrote this little test-program:

#include 
#include 
#include 

        
2条回答
  •  既然无缘
    2021-01-02 17:22

    It works as expected.

    I'm not sure what you are expecting...

    Is this allowed?

    That's probably not portable. Streams relies on char_traits and on facets which are defined in the standard only for char and wchar_t. An implementation can provides more, but my bet would be that you are relying on a minimal default implementation of those templates and not on a conscious implementation for int. I'd not be surprised that a more in depth use would leads to problems.

提交回复
热议问题