visual c++ doesn't understand u'' and U'' literals [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
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.

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.

Related

How to use unicode in C++ without much pain? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
Improve this question
In C++ there's no solid standard when it comes to encoding. If I want to use unicode, for example, UTF-8 in C++ for Windows, how can I achieve that?
On Windows I have to use something like wide-strings to use unicode, is it the only way?
If I have to use third-party libraries, what libraries do you can advise?
What I have to remember when using unicode instead of std::string?
If you are talking about source code, then its implementation specific for each compiler, but I believe every modern compiler supports UTF-8 at least.
C++ itself has following types to support Unicode:
wchar_t, char16_t, char32_t and char8_t for characters and corresponding std::wstring, std::u16string, std::u32string and std::u8string for strings.
And following notations for literals:
char8_t ch_utf8 = u8'c';
char16_t ch_utf16 = u'c';
char32_t ch_utf32 = U'C';
wchar_t ch_wide = L'c';
char8_t str_utf8[] = u8"str";
char16_t str_utf16[] = u"str";
char32_t str_utf32[] = U"str";
wchar_t str_wide[] = L"str";
std::codecvt template for string conversions between different encodings.

How can I best use UTF-8 for text in Windows program development? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 12 months ago.
Improve this question
I've just started doing some Windows programming.
I'm trying to decide how best to handle non-ASCII text.
I'd prefer to use 8-bit characters rather than 16-bit i.e. declare all my strings as char.
I've read the UTF-8 Everywhere proposals, and I think they misrepresent the current state of Windows.
Since Windows 10 version 1803 (10.0.17134.0) support for a UTF-8 page has been implemented to the same standard as other multibyte character encodings.
I think now that I can:
Ensure Visual Studio uses UTF-8 to store source code using an EditorConfig file and use UTF-8 strings by specifying '/utf-8' as an "additional" option in the C/C++/Command Line
Make sure the system knows the program is using UTF-8 character strings by calling setlocale(LC_ALL,".UTF-8"); and/or setting <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage> in the manifest. (The system will actually expect UTF-8 by default if 'Beta: Use Unicode UTF-8 for worldwide language support' is ticked in Region/Language/Administrative language settings/Region Settings - I believe this sets the active code page to UTF-8, and is the default for Windows 11).
Don't define UNICODE and _UNICODE in source, and so use the Win32 'Ansi' interfaces. Windows will convert any text to UTF-16 internally.
Use the standard strings and char variables I'm used to, rather than wstring and wchar.
Have I got this right?
Is there anything else I need to do, apart from watching out for any code that in some way depends on a single character being held in a single byte?
Or is there some gotcha that is waiting to trip me?

Should I use TCHAR today [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am starting to work on a completely new project for Windows Desktops written in C++. When I learned Windows programming, I read that using TCHAR is a great improvement because I can build an ANSI or a Unicode version of my program without changing the code. However, I never really used the option to build the ANSI version. Moreover, in the standard library of C++, there is no TCHAR, I have to create typedefs for std::string, std::stringstream, etc. and their wide string counterparts. So currently I am thinking of abandoning TCHAR in favor of wchar_t, and I collected the following advantages and disadvantages.
Advantages:
TCHAR is a macro, so if I don't use it, the front-end compiler and Intellisense will give better results.
It is more explicit what the type of a variable is.
L"" is easier to type than _T("").
Disadvantages:
Loss of modularity regarding the character type (even though I don't really need the ANSI version, I find using an abstract character type to be a neat feature, and what if in the future I will need a UTF-8 or UTF-32 version?).
I would have to postfix some API functions with W, like GetWindowTextW.
And my questions:
Is there an easier way in the C++ standard library to use TCHAR than the one I described above? Like a standard header file that has these typedefs?
Do you think that my reasoning is correct?
Do I miss any important point?
What is the state-of-the-art solution today? Do professional Windows programmers still use TCHAR (in new code)?
If I remove TCHAR, than should I write L"" or u"" instead of _T("")?
In modern windows all ANSI functions are internally converting char* to wchar_t* and calling unicode versions of same function. Basically, by adopting TCHAR instead of wchar_t you gain nothing, but have to deal with quirky syntax.

Is there any way to understand Visual Studio 2012 hints while writing C++ code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there any way to understand the meaning of _Ux, _Dx, _Dt here? This mnemonics tells me nothing about parameters.
These "mnemonics" as you call it are nothing but a hint generated by Visual Studio's IntelliSense that is meant to help you while writing the code (syntax) rather than the meaning (semantics).
If you need more information to help you understand the API and its proper usage, you should rather consult the documentation. In this case it might be the reference for std::shared_ptr's constructor
This "weird names" thing has (at least partly) to do with reserved identifiers. The programmer (you, me) is not allowed to define names like _Ux that begin with an underscore followed by a capital letter (nor names like __x or a__b that contain adjacent underscores) anywhere in his source code. The C++ implementation (Standard Library details, compiler internals...) can thus use this reserved "name space" without fearing name clashes with user code.
That's a win-win: the implementation will never define names like fooBar or FOO_BAR (set aside keywords like int and public names like std, printf or CHAR_BIT), so you can safely use these names in your code, and reciprocally you should never define names like _FooBar, __foo_bar or FOO__BAR, so that you won't mess up with the implementation (this is especially true for macros).
As for why they use _Ux * _Px, _Dx _Dt and not e.g. _U * __p, _Deleter __d (also _Ty and not _T), well, I guess that it's simply their internal naming conventions.

What is a "Unix-like" compiler? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
On the Wikipedia List Of Compilers page, it tells you if a compiler is "Unix-like". What does this mean? Does it effect how to write the source code? I'm coming over from MinGW (which is listed as "Unix-like" to another compiler, just wanted to see if this was a important thing to look out for).
I think you miss-understand. That column indicates if your compiler is available on a "unix-like" OS/platform, of which linux is an example.
You can see this by the fact that MingGW is listed under the windows column for compilers (GCC) which are available on many platforms, which means that MinGW is the windows port/version of GCC (in the context of this question).