0

I use visual studio 2013. When I write this code

char16_t ch1 = u'q';

visual studio complains with Error: identifier "u" is undefined. I thought VS 2013 should support c++11 standard and u'' identifier as well.

Dumas45
  • 501
  • 1
  • 10
  • 20
  • 1
    I don't think VS have complete C++ standard support ever. Try `L'q'` – phuclv May 30 '14 at 08:11
  • `u` is for `unsigned` int/long etc. for character type, use `L'q'` – Rakib May 30 '14 at 08:11
  • 3
    Please check the [support table](http://msdn.microsoft.com/en-us/library/hh567368.aspx) before posting questions, no version of VS currently supports `char16_t` / `char32_t`. – user657267 May 30 '14 at 08:13
  • 5
    This question appears to be off-topic because the information is readily available online. – user657267 May 30 '14 at 08:20
  • No compiler currently supports C++11 completely. – James Kanze May 30 '14 at 08:26
  • 1
    Is there any special reason you need `char16_t` specifically rather than just `wchar_t`? – Mario May 30 '14 at 08:27
  • @Mario portability? :p – jalf May 30 '14 at 08:30
  • @jalf Last time I tried, my Linux system understood `wchar_t` and even Android does so (using some tricks). If you'd like to exchange files or strings over the net, you'll just have to ensure to use the proper encoding on both ends. – Mario May 30 '14 at 08:34
  • @user VS 2013 supports char16_t and char32_t types. If I write this – Dumas45 May 30 '14 at 08:48
  • @user VS 2013 does support char16_t and char32_t types. If I write this char16_t ch1 = 105; it woldn't be mistake. That's why I wondered why U'' literal is still unavailable. – Dumas45 May 30 '14 at 08:51
  • @Dumas45 Both are marked as not supported in the table, they may have forgotten to update the table for `char16_t` after the last update, but either way unicode literals are quite obviously not supported. – user657267 May 30 '14 at 08:53
  • 1
    use [`wchar_t`](http://en.cppreference.com/w/cpp/keyword/wchar_t), that's the C++ keyword and guaranteed to be available on all compilers that support Unicode. Also, [`L` prefix](http://stackoverflow.com/questions/13087219/what-exactly-is-the-l-prefix-in-c) is much more common – phuclv May 30 '14 at 09:19

1 Answers1

4

While Microsoft's Visual C++ 2013 supports many C++11 features, the support still isn't complete.

As for string literals, they support only two (or three; depending on how you count) string literal prefixes so far:

  • L"Hello \"World\"" using Lto mark wide character strings (i.e. wchar_t rather than char).
  • R"(Hello "World")" using R to mark raw strings with special user defined delimiters (new to C++11).
  • LR"(Hello "World")" using a combination of both.
Mario
  • 35,726
  • 5
  • 62
  • 78