Re: Multi width char initialization - I'll just always use wchar_t

Discussion in 'C++' started by Jim Langston, Oct 22, 2010.

  1. Jim Langston

    Jim Langston Guest

    "Jim Langston" <> wrote in message
    news:i9r7kq$hqr$...
    > This snippet will not compile:
    >
    > typedef char char_type;
    > std::basic_string<char_type> output( L"Syntax error." );
    >
    > The reason being std::basic_string<char> can be constructed from a char*
    > but not a wchar_t*. If I change it from L"Syntax error." to "Syntax
    > error." then it won't compile when char_type is wchar_t. I intend on
    > supporting up to u32 or higher so this is a quandry.
    >
    > I tried:
    > #define CTP_ L
    > std::basic_string<char_type> output( CTP_"Syntax error." );
    > but got:
    > error C2065: 'L' : undeclared identifier
    >
    > and I'd rather use templates if possible than defines. Any ideas?


    Thinking about it, I'll just use wchar_t should support every character
    currently used so I can just use it.
    Jim Langston, Oct 22, 2010
    #1
    1. Advertising

  2. Jim Langston

    Geoff Guest

    On Fri, 22 Oct 2010 11:07:24 -0700, "Jim Langston"
    <> wrote:

    >
    >"Jim Langston" <> wrote in message
    >news:i9r7kq$hqr$...
    >> This snippet will not compile:
    >>
    >> typedef char char_type;
    >> std::basic_string<char_type> output( L"Syntax error." );
    >>
    >> The reason being std::basic_string<char> can be constructed from a char*
    >> but not a wchar_t*. If I change it from L"Syntax error." to "Syntax
    >> error." then it won't compile when char_type is wchar_t. I intend on
    >> supporting up to u32 or higher so this is a quandry.
    >>
    >> I tried:
    >> #define CTP_ L
    >> std::basic_string<char_type> output( CTP_"Syntax error." );
    >> but got:
    >> error C2065: 'L' : undeclared identifier
    >>
    >> and I'd rather use templates if possible than defines. Any ideas?

    >
    >Thinking about it, I'll just use wchar_t should support every character
    >currently used so I can just use it.


    To quote Dr. Joseph M. Newcomer [MVP] from microsoft.public.vc.mfc
    fame: "Forget char exists."
    Geoff, Oct 22, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndrewF
    Replies:
    1
    Views:
    741
    Bruce Barker
    Oct 10, 2005
  2. Deryck
    Replies:
    4
    Views:
    508
    derek giroulle
    Jun 22, 2004
  3. Petter Reinholdtsen

    char array initialization: Is 'char a[] = ("a")' valid ANSI C?

    Petter Reinholdtsen, Nov 1, 2004, in forum: C Programming
    Replies:
    20
    Views:
    1,030
    Dave Thompson
    Nov 22, 2004
  4. lovecreatesbeauty
    Replies:
    1
    Views:
    1,011
    Ian Collins
    May 9, 2006
  5. Replies:
    3
    Views:
    1,083
    James Kanze
    Aug 15, 2008
Loading...

Share This Page