Click here to Skip to main content
Click here to Skip to main content

Some useful additions for the C++ standard library

By , 11 Apr 2000
 
  • Download source files - 3 Kb
  • This is some simple, but useful code for STL users. It defines some TCHAR compatible elements of STL:

    _tstring	- wstring or string
    _tostream	- wostream or ostream
    _tistream	- wistream or istream
    
    _tcout	- wcout or cout
    _tcin	- wcin or cin
    _tcerr	- wcerr or cerr
    _tclog	- wclog or clog
    
    It gives you a std::ostream to dump objects into the debugger window, some string functions and adds support for __int64 types.

    No really fancy stuff, but you may need it :-)

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Daniel Lohmann
    Germany Germany
    Member
    Daniel Lohmann (daniel@losoft.de) is Assistant Professor at the Distributed Systems and Operating Systems department at Friedrich-Alexander-University Erlangen-Nuremberg, Germany. His main research topic is the design of a highly customizable and scalable operating system product line for deeply embedded systems using static configuration and aspect-oriented techniques. Before joining Universität Erlangen he worked as a freelance trainer and consultant for NT system programming, advanced C++ programming and OOA/OOD. He is interested in upcoming programming techniques like aspect-oriented programming, generative programming and C++ meta coding and has written some nice and handy tools for Windows NT which you can download at his web site.

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    QuestionTimer events codememberLLKHANBARI15 Jul '07 - 8:57 
    I am looking for a simple code in C++ to use in my program. Acually my program should run for a specific time (minutes or hours)and after this time finishes, the program should output the results.
     
    Thanking you

    Questionxsputn really needed ?suss__gui_gui__27 Dec '04 - 6:39 
    Thanks for your debugbuf, it looks nice and clean except for one thing : Why did you overloaded xsputn ? I don't understand why you mess around with this method.
     
    I didn't compile your code but lots of chances are if you comment out the function, it'll still work.
     
    Greets.
    AnswerRe: xsputn really needed ?memberDaniel Lohmann29 Dec '04 - 4:34 
    Uh, oh, that was a long time ago... Confused | :confused:
     
    Well, AFAIR I did so for performance and thread safety. Remember that CEditLog was intended to be used by multiple threads simultaneously that may render messages with a very high frequency. Therefore it is necessary that the streaming of a block of data (lets say a line) takes place quickly and uninterruptable, otherwise the output would be slow and messy, as messages from different threads get mixed up.
    Both, efficiency and atomicity is ensured by the own xsputn() implementation, which protects the access to the shared buffer by a critical section and copies chunks of data blockwise instead of char by char. AFAIR.
     

     
    --
     
    Daniel Lohmann
     
    http://www.losoft.de
    (Hey, this page is worth looking! You can find some free and handy NT tools there Big Grin | :-D )
    GeneralRe: xsputn really needed ?memberHenry Bruce30 Jul '07 - 8:27 
    Daniel is correct.
     
    Without this apporach, the stream is not thread-safe. For some empirical proof, trying using the simpler stream object at http://www.codeproject.com/debug/debugout.asp.
     
    Henry

    QuestionI want to creat a Min heap,how can I do it?memberTheWay15 Jan '03 - 5:17 
    #include <iostream>
    #include <algorithm>
    #include <time.h>
    #include <queue>
    #include <functional>
     
    using namespace std ;
    void Init(int& x)
    {
         x=rand()%1000;
    }
    void out(const int& x)
    {
         cout<<x<<" ";
    }
     
    void main()
    {
         srand(time(NULL));
         int *A=new int[20];
         for_each(&A[0],&A[20],Init);
         for_each(&A[0],&A[20],out);
         cout<<endl;
         priority_queue<int> x(&A[0],&A[20]);
         //I want to creat a Min heap,how can I do it in priority_queue?
    //     priority_queue<int> x(&A[0],&A[20],greater<int>());
     
         delete []A;
         for(int i=0;i<20;++i)
         {
              cout<<x.top()<<" ";
              x.pop();
         }
    }

    GeneralDon't use #define, it confuses debuggersmemberBen Berck17 Jan '02 - 10:26 
    As we all know, #define's are secrets to debuggers, and therefore quite annoying.
     
    The following will not confuse the debuggger:
     
    #include
    #include
    #include
    using namespace std;
     
    typedef basic_ostream tostream;
    #ifdef _UNICODE
    tostream& tcout = wcout;
    #else
    tostream& tcout = cout;
    #endif
     
    int main(int argc, char* argv[])
    {
    tcout << _T("Test 123");
    return 0;
    }

     
    Ben Berck
    Semi-retired C++ guy
    GeneralCode repost: fix angle bracketsmemberBen Berck17 Jan '02 - 10:31 
    Sorry, didn't catch the angle bracket problem when pasting the code.
     
    #include <tchar.h>
    #include <iostream>
    #include <ostream>
    using namespace std;
     
    typedef basic_ostream<TCHAR> tostream;
    #ifdef _UNICODE
    tostream& tcout = wcout;
    #else
    tostream& tcout = cout;
    #endif
     
    int main(int argc, char* argv[])
    {
    tcout << _T("Test 123");
    return 0;
    }

     
    Ben Berck
    Semi-retired C++ guy
    GeneralRe: Code repost: fix angle bracketsmemberChristian Graus17 Jan '02 - 12:49 
    Of course, if we're being picky, using namespace std is a colossally bad idea...

     
    Christian
     
    I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
     
    Sonork ID 100.10002:MeanManOz
    I live in Bob's HungOut now

    GeneralRe: Code repost: fix angle bracketsmemberDaniel Lohmann18 Jan '02 - 0:07 
    Christian Graus wrote:
    Of course, if we're being picky, using namespace std is a colossally bad idea...
     
    Of course. Wink | ;) Blush | :O
     
    --
     
    Daniel Lohmann
     
    http://www.losoft.de
    General~basic_dbgstreambuf() needs a tiny fixmemberGirish Zambre9 Apr '01 - 12:49 
    In "~basic_dbgstreambuf()" the statement "delete psz;" should be "delete [] psz;" since "psz" was allocated with "new char_type[ BUF_SIZE ]" in "basic_dbgstreambuf()".
    GeneralThe _stringf function is cool, but needs a bit morememberCodeSkunk15 Nov '00 - 11:11 
    the "_stringf" function doesn't allocate exactly what it needs. Sure would be cool if the buffer size wasn't allocated via a const size.
    MFCs CString::Format function is similar, but they parse the mask and variables to determine the length required for the string. Unfortunatley if any of the masks change for sprintf, it will break in addition to it not being protable.
    I don't like either method, but don't offer a better solution. I am working on that.
    GeneralDon't use underscores.sussJames Curran 13 Apr '00 - 6:10 
    It seems people like uses leading underscores in identifier names. Don't do this. The ISO C++ Standard specifically reserves names starting with an underscore to the compiler vender (see 17.4.3.1.2)
    GeneralRe: Don't use underscores.sussAlvaro Mendez15 May '00 - 13:06 
    I think the author was simply following the Microsoft convention for their character string functions, like _tcscpy, _tcscmp, etc...
    GeneralRe: Don't use underscores.sussJames 15 May '00 - 16:57 
    But Microsoft is allowed: They're the compiler vendor...

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web03 | 2.6.130516.1 | Last Updated 12 Apr 2000
    Article Copyright 2000 by Daniel Lohmann
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid