How do I write a map literal in C++11? [duplicate]

You can actually do this: std::map<std::string, int> mymap = {{“one”, 1}, {“two”, 2}, {“three”, 3}}; What is actually happening here is that std::map stores an std::pair of the key value types, in this case std::pair<const std::string,int>. This is only possible because of c++11’s new uniform initialization syntax which in this case calls a constructor overload … Read more

Assigning 128-bit integer in C

Am I doing something wrong or is this a bug in gcc? The problem is in 47942806932686753431 part, not in __uint128_t p. According to gcc docs there’s no way to declare 128 bit constant: There is no support in GCC for expressing an integer constant of type __int128 for targets with long long integer less … Read more

Backslashes in single quoted strings vs. double quoted strings

Double-quoted strings support the full range of escape sequences, as shown below: \a Bell/alert (0x07) \b Backspace (0x08) \e Escape (0x1b) \f Formford (0x0c) \n Newline (0x0a) \r Return (0x0d) \s Space (0x20) \t Tab (0x09) \v Vertical tab (0x0b) For single-quoted strings, two consecutive backslashes are replaced by a single backslash, and a backslash … Read more

Are string literals const?

They are of type char[N] where N is the number of characters including the terminating \0. So yes you can assign them to char*, but you still cannot write to them (the effect will be undefined). Wrt argv: It points to an array of pointers to strings. Those strings are explicitly modifiable. You can change … Read more

Should I use _T or _TEXT on C++ string literals?

A simple grep of the SDK shows us that the answer is that it doesn’t matter—they are the same. They both turn into __T(x). C:\…\Visual Studio 8\VC>findstr /spin /c:”#define _T(” *.h crt\src\tchar.h:2439:#define _T(x) __T(x) include\tchar.h:2390:#define _T(x) __T(x) C:\…\Visual Studio 8\VC>findstr /spin /c:”#define _TEXT(” *.h crt\src\tchar.h:2440:#define _TEXT(x) __T(x) include\tchar.h:2391:#define _TEXT(x) __T(x) And for completeness: C:\…\Visual Studio … Read more