string-literals

conflicts: definition of wchar_t string in C++ standard and Windows implementation?

走远了吗. 提交于 2019-12-04 03:10:14
问题 From c++2003 2.13 A wide string literal has type “ array of n const wchar_t ” and has static storage duration, where n is the size of the string as defined below The size of a wide string literal is the total number of escape sequences, universal-character-names, and other characters, plus one for the terminating L’\0’. From c++0x 2.14.5 A wide string literal has type “ array of n const wchar_t ”, where n is the size of the string as defined below The size of a char32_t or wide string literal

What's the “E” before a Postgres string?

£可爱£侵袭症+ 提交于 2019-12-04 02:46:45
问题 I was reading a Postgres/PostGIS statement like this: SELECT ST_AsBinary( ST_GeomFromWKB( E'\\001\\001\\000\\000\\000\\321\\256B\\312O\\304Q\\300\\347\\030\\220\\275\\336%E@', 4326 ) ); The above creates something from a Well Known Binary (WKB). I haven't seen the specific way of quoting here where the string is single quoted with a E preceding the beginning quote. What is this format called? And what are the formatting rules for this? e.g. is the 336%E@ at the very end special or just some

The difference between char* and int*

半世苍凉 提交于 2019-12-04 02:03:20
What is the difference between char* and int* ? Sure, they are of different types, but how is it that I can write char* s1="hello world"; as "hello world" it is not a one character, it's an array of characters, and I cannot write *s1 as char* s1 = {'h','e','l','l','o',' ','w','o','r','l','d'}; and int* a = {2,3,1,45,6}; What is the difference? It is quite simple: A string literal, i.e., "foobar" is compiled to an array of chars which is stored in the static section of your program (i.e., where all constants are stored) and null terminated. Then, assigning this to a variable simply assigns a

Why can a string literal be implicitly converted to char* only in certain case? [duplicate]

こ雲淡風輕ζ 提交于 2019-12-04 00:31:16
This question already has answers here : Closed 6 years ago . Why is passing a string literal into a char* argument only sometimes a compiler error? (6 answers) void f(char* p) {} int main() { f("Hello"); // OK auto p = "Hello"; f(p); // error C2664: 'void f(char *)' : cannot convert parameter 1 // from 'const char *' to 'char *' } The code was compiled with VC++ Nov 2012 CTP. §2.14.15 String Literals, Section 7 A narrow string literal has type “array of n const char”, where n is the size of the string as defined below, and has static storage duration. Why is f("Hello") OK? This behaviour

Keeping code structure with string literal that uses whitespace

心不动则不痛 提交于 2019-12-03 22:16:47
So a bit of a weird question I was having trouble coming up with the search terms for. If I have a multi-line string literal in my program, is there anyway to keep the indentation of my code consistent without adding unwanted white space to my string literal? Ex: if (true) { if (!false) { //Some indented code; stringLiteral = string.format( @"This is a really long string literal I don't want it to have whitespace at the beginning of each line, so I have to break the indentation of my program I also have vars here {0} {1} {2}", var1, var2, var3); } } It's probably just my OCD talking, but is

Is it possible to initialise a character array with a conditionally selected string literal?

假装没事ソ 提交于 2019-12-03 16:06:34
问题 I know it's perfectly possible to initialise a char array with a string literal: char arr[] = "foo"; C++11 8.5.2/1 says so: A char array (whether plain char , signed char , or unsigned char ), char16_t array, char32_t array, or wchar_t array can be initialized by a narrow character literal, char16_t string literal, char32_t string literal, or wide string literal, respectively, or by an appropriately-typed string literal enclosed in braces. Successive characters of the value of the string

How can I escape special symbols in scala string?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 15:39:53
Is there a general Scala utility method that converts a string to a string literal? The simple lambda function "\"" + _ + "\"" only works for strings without any special characters. For example, the string \" (length 2) should be converted to the string "\\\"" (length 6). Have a look at Apache Common's StringEscapeUtils class ( docs here ). escapeJava should get the job done. Have a look at this example to see it in action (in Java). Wrap the String with 3 quotes to represent it as is.. e.g. val str = """ \" """ // str : java.lang.String = \" 来源: https://stackoverflow.com/questions/17341079

How safe and reliable are C++ String Literals?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 14:37:45
So, I'm wanting to get a better grasp on how string literals in C++ work. I'm mostly concerned with situations where you're assigning the address of a string literal to a pointer, and passing it around. For example: char* advice = "Don't stick your hands in the toaster."; Now lets say I just pass this string around by copying pointers for the duration of the program. Sure, it's probably not a good idea, but I'm curious what would actually be going on behind the scenes. For another example, let's say we make a function that returns a string literal: char* foo() { // function does does stuff

String Literal Differences Between C and C++

ぃ、小莉子 提交于 2019-12-03 07:01:25
问题 As far as I can tell, before C++11, string literals were handled in almost exactly the same way between C and C++. Now, I acknowledge that there are differences between C and C++ in the handling of wide string literals. The only differences that I have been able to find are in the initialization of an array by string literal. char str[3] = "abc"; /* OK in C but not in C++ */ char str[4] = "abc"; /* OK in C and in C++. Terminating zero at str[3] */ And a technical difference that only matters

What does %S mean in PHP, HTML or XML?

旧城冷巷雨未停 提交于 2019-12-03 06:23:36
问题 I'm looking at Webmonkey's PHP and MySql Tutorial, Lesson 2. I think it's a php literal. What does %s mean? It's inside the print_f() function in the while loops in at least the first couple of code blocks. printf("<tr><td>%s %s</td><td>%s</td></tr>n", ... 回答1: with printf or sprintf characters preceded by the % sign are placeholders (or tokens). They will be replaced by a variable passed as an argument. Example: $str1 = 'best'; $str2 = 'world'; $say = sprintf('Tivie is the %s in the %s!',