Click here to Skip to main content
12,999,417 members (50,364 online)
Click here to Skip to main content


35 bookmarked
Posted 11 Feb 2006

A TCHAR style header file for STL strings and streams

, 11 Feb 2006
Presents a header file that allows a single source file that uses STL to be built in either ANSI or Unicode, without any changes or lots of #ifdefs.
// tstl.h - header file for TCHAR equivalents of STL string classes
// Copyright (c) 2006 PJ Arends
// This file is provided "AS-IS". Use and/or abuse it in any way you feel fit.
#pragma once

#include <string>
namespace std
#if defined UNICODE || defined _UNICODE
    typedef wstring         tstring;
    typedef wstringbuf      tstringbuf;
    typedef wstringstream   tstringstream;
    typedef wostringstream  tostringstream;
    typedef wistringstream  tistringstream;
    typedef wstreambuf      tstreambuf;
    typedef wistream        tistream;
    typedef wiostream       tiostream;
    typedef wostream        tostream;
    typedef wfilebuf        tfilebuf;
    typedef wfstream        tfstream;
    typedef wifstream       tifstream;
    typedef wofstream       tofstream;
    typedef wios            tios;
#   define tcerr            wcerr
#   define tcin             wcin
#   define tclog            wclog
#   define tcout            wcout
#else // defined UNICODE || defined _UNICODE
    typedef string          tstring;
    typedef stringbuf       tstringbuf;
    typedef stringstream    tstringstream;
    typedef ostringstream   tostringstream;
    typedef istringstream   tistringstream;
    typedef streambuf       tstreambuf;
    typedef istream         tistream;
    typedef iostream        tiostream;
    typedef ostream         tostream;
    typedef filebuf         tfilebuf;
    typedef fstream         tfstream;
    typedef ifstream        tifstream;
    typedef ofstream        tofstream;
    typedef ios             tios;
#   define tcerr            cerr
#   define tcin             cin
#   define tclog            clog
#   define tcout            cout
#endif // defined UNICODE || defined _UNICODE
} // namespace std

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

PJ Arends
Canada Canada
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 12 Feb 2006
Article Copyright 2006 by PJ Arends
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid