trying to get basic_ostream template to use TCHARs

This is a discussion on trying to get basic_ostream template to use TCHARs within the C++ Programming forums, part of the General Programming Boards category; The below code is not the way I want to have ostream/wostream managed by the #define _UNICODE for ansi or ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    156

    trying to get basic_ostream template to use TCHARs

    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.

    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;
    }
    The way I'd like to get things working:

    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;
    }
    This gives the error:
    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
    Last edited by Dang; 09-13-2001 at 10:08 PM.

  2. #2
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    Posts
    109
    Code:
    inline tostream& operator<< (tostream& os, 
                                const tstring& tstring)
    {
    	os << tstring.data( );
    
    	return os;
    }
    You're using here defined type 'tstring' as a variable name (const tstring& tstring)
    Making error is human, but for messing things thoroughly it takes a computer

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    Thanks that was clearly a bug but didn't fix it. I've abandon that approach and trying another path. Thanks for your help.


    thanks


    dang

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 05:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 09:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21