Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > IT > Programming > C++ Programming > Professional C++ > Professional C++: String

String

Raw string literal

Raw string literal can be used to write a string of multiple lines or containing special chars without using escaped chars. The format is: R"(...)", and the extended format (used to handle the case when there are ')"' in the string) is: R"<delim-char-seq>(...)<delim-char-seq>".

<delim-char-seq>:

  • max number of chars in it is 16
  • iDog: it seems that it cannot either ')' or '('

const char* pszOld1 = "Line1\nLine2";
const char* pszNew1 = R"(Line1
Line2)";

const char* pszOld2 = "Hello, \"world\"!";
const char* pszNew2 = R"(Hello, "world"!)";

const char* pszOld3 = "Tab: \\t";
const char* pszNew3 = R"(Tab: \t)";

const char* psz = R"--(a string containing ')"'.)--";   // iDog: it seems that the <delim-char-seq> cannot contain '(' or ')'