c++ - Accept multiple types using one stringstream function parameter -


i need implement own stream class error writing cout. here im going create separate class , overload << operator accept basic data types. simple idea fallow. program not compiled.

error error c2679: binary '<<' : no operator found takes right-hand operand of type 'const wchar_t [20]' (or there no acceptable conversion)

#include <iostream> #include <string>  #include <sstream>  class errorwriter { public: std::wstringstream& errorwriter::operator<<(std::wstringstream& ss){         //write file       //write console         return ss;     } };  int main(){   errorwriter eout;   eout << l"this first error";   eout << l"\nthis second error" << 1 << 2.5 << true; } 

so question

  1. how accept basic type argument using 1 function parameter (i not need write multiple operate overloader each data type).
  2. how other streams cout ,stringstream implement this
  3. wstringstream can constructed wchar_t

    std::wstringstream ss(l"this first error");

so why cannot convert wstringstream on fly (by works conversion constructor)

  1. don't think there obvious way this.

  2. the basic_stringstream constructor taking string declared explicit - hence conversion doesn't automatically happen.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -