1
wstring ss;
ss << L"Some wide-char text" << " and some non-wide-char text";

This appears to work just fine but why, when char_type is not char?

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • ss << L"Some wide-char text" what is L? – Ankur Jan 05 '15 at 11:13
  • 2
    @shan http://stackoverflow.com/questions/6384118/what-does-the-l-in-front-a-string-mean-in-c – Mr. Boy Jan 05 '15 at 11:14
  • 1
    Next time please explain why you expected some other behaviour. For those of us who know the answer already, it may not be clear what your false expectations were. For example _"I don't see how this is working"_ **Why?** Did you read some documentation that suggested that it wouldn't? Did you interpret the standard in a way that led you to believe that it wouldn't? Can you provide evidence of this research and point us to the material that led you to your conclusion? Y'know, sciencey stuff. – Lightness Races in Orbit Jan 05 '15 at 12:24
  • I'm not sure it's unclear but I've tweaked the question a little, does that make it more obvious why I was confused? I think @user657267 answered the question I _meant_ to ask? – Mr. Boy Jan 05 '15 at 12:35

2 Answers2

1

All streams have overloads for char, regardless of the CharT of the template.

http://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt2

template< class CharT, class Traits >
basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, 
                                         const char* s );
user657267
  • 20,568
  • 5
  • 58
  • 77
0

Because it is.

Exactly std::char_traits<char>::length(s) characters are inserted.
Before insertion, first, all characters are widened using os.widen().

(source)

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055