none
建立unicode,ansi通吃的STL string RRS feed

  • 问题

  •  tchar.h中一些宏如TCHAR _T可以对付unicode和ansi,mfc中CString类也有此能力。不知STL中的string有没有这样的类?我目前就知道有个wstring专门处理宽字符的。于是我想仿照string定义自己定义一个这样的类:

    #include <tchar.h>

    typedef basic_string<TCHAR> tstring;    //OK

    //实现输出
    typedef basic_ostream<TCHAR> tostream; //OK
    tostream tcout;                    //??相当于cout,这里该如何写,在cout上点Go to definition只有其声明,不知cout如何定义的??
    2009年2月6日 5:26

答案

  • 使用宏来做吧

     #ifdef UNICODE  
    #    define tstring wstring
    #else  
    #    define tstring string
    #endif 
    2009年2月6日 9:08
  • C99 added some support for Unicode characters, both within string literals and in identifiers. In practice, the system support for this probably isn't where it needs to be for most users; don't expect source that uses this to be accessible to other people just yet. In general, the wide character and unicode support is mostly there in the compiler, but the text processing tools aren't quite up to par yet.

    MSMVP VC++
    2009年2月6日 15:06
    版主

全部回复

  • 使用宏来做吧

     #ifdef UNICODE  
    #    define tstring wstring
    #else  
    #    define tstring string
    #endif 
    2009年2月6日 9:08
  • C99 added some support for Unicode characters, both within string literals and in identifiers. In practice, the system support for this probably isn't where it needs to be for most users; don't expect source that uses this to be accessible to other people just yet. In general, the wide character and unicode support is mostly there in the compiler, but the text processing tools aren't quite up to par yet.

    MSMVP VC++
    2009年2月6日 15:06
    版主