The below code is not the way I want to have ostream/wostream managed by the #define _UNICODE for ansi or unicode but it appears to work. I've only done simple testing and would have to add more #defines for cerr, wcerr, clog, etc... After that not so pretty code there's another that attempts use the basic_ostream template and the error I'm getting. Once I get that going I can work on basic_istream.
The way I'd like to get things working:Code:#include "stdafx.h" #define _UNICODE #include <tchar.h> #include <iostream> #include <string> using namespace std; #ifdef _UNICODE #define TCOUT wcout #define TCIN wcin #else #define TCOUT cout #define TCIN cin #endif typedef basic_string<TCHAR> tstring; int main(int argc, char* argv[]) { TCOUT << _T("Enter anything: ") << endl; tstring z; TCIN >> z; TCOUT << z << endl; tstring f = _T( "test" ); TCOUT << f << endl; return 0; }
This gives the error:Code:#include "stdafx.h" #define _UNICODE //must be before tchar.h #include <tchar.h> #include <iostream> #include <string> using namespace std; typedef basic_string<TCHAR> tstring; typedef basic_ostream<TCHAR, char_traits<TCHAR> > tostream; tostream tcout(); inline tostream& operator<< (tostream& os, const tstring& tstring) { os << tstring.data( ); return os; } int main(int argc, char* argv[]) { tstring s = _T("Test"); tcout << s << endl; return 0; }
error C2678: binary '<<' : no operator defined which takes a left-hand operand of type '' (or there is no acceptable conversion)
Any suggestion would be appreciated.
thanks
dan



LinkBack URL
About LinkBacks


