Why is it that wcout << “”; is OK but wcout << string(); is not?

前端 未结 2 1065
我在风中等你
我在风中等你 2021-01-01 18:12
#include 
#include 

using namespace std;

int main()
{
    wcout << L\"Hello\";          // OK.
    wcout << wstring(L\"He         


        
2条回答
  •  死守一世寂寞
    2021-01-01 18:26

    For the first one, I'm guessing this overload is used:

    template< class CharT, class Traits >
    basic_ostream& operator<<( basic_ostream& os, 
                                             const char* s );
    

    Where wstream is essentially a basic_ostream.

    For why string("Hello") doesn't work, it's simply because there is no conversion from string to wstring, nor an overload of operator<< provided.

提交回复
热议问题