I don’t know whether you don’t understandRor notxxx, so I’ll tell you everything
Let me start with R, which represents Raw String
For example, the following text
abc
efg\n
Before there was Raw String, you had to write like this
"abc\n\tefg\n"
Special symbols in the string must be escaped
But after having Raw String, you can write like this
R"(abc
efg\n)"
That is, the text inside the brackets Raw String is What you see is what you get
Maybe you are wondering, why do you need a pair of parentheses?
Think about the text
abc"efg
If there are no brackets, it will be written as R"abc"efg", so it is impossible to determine which is the paired double quote , so brackets need to be introduced to delimit
After introducing brackets, what if there are quotation marks + brackets in the original text? For example
abc)"efg
According to the above writing method, it needs to be written as R"(abc)"efg)", which will obviously lead to grammatical errors and it will be impossible to determine which pair is )" Obviously, when the text contains )" , () is not enough to delimit
Therefore, you need to customize delimiter (delimiter) , which is the xxx(...)xxx in your question. The string above can be written as R"xxx(abc)"efg)xxx", and is compiled like this The programmer will be able to tell that everything contained in xxx(...)xxx is the original text. Of course, xxx can be customized by you. You can also write it as ab(...)ab
That is, the characters between the brackets will not be escaped and will be output as is. Because "" is used frequently in regular expressions, this method avoids the problem of converting "" into "\". For example:
"('(?:[^\']|\.)*'|"(?:[^\"]|\.)*")|"
If you don’t use this method, you need to write it like this:
I don’t know whether you don’t understand
R
or notxxx
, so I’ll tell you everythingLet me start with
R
, which representsRaw String
For example, the following text
Before there was
Raw String
, you had to write like thisSpecial symbols in the string must be escaped
But after having
Raw String
, you can write like thisThat is, the text inside the brackets
Raw String
is What you see is what you getMaybe you are wondering, why do you need a pair of parentheses?
Think about the text
If there are no brackets, it will be written as
R"abc"efg"
, so it is impossible to determine which is the paired double quote, so brackets need to be introduced to delimit
After introducing brackets, what if there are quotation marks + brackets in the original text?
For example
According to the above writing method, it needs to be written as
R"(abc)"efg)"
, which will obviously lead to grammatical errors and it will be impossible to determine which pair is)"
Obviously, when the text contains
)"
,()
is not enough to delimitTherefore, you need to customize
delimiter
(delimiter) , which is thexxx(...)xxx
in your question. The string abovecan be written as
R"xxx(abc)"efg)xxx"
, andis compiled like this The programmer will be able to tell that everything contained in
xxx(...)xxx
is the original text.Of course,
xxx
can be customized by you. You can also write it asab(...)ab
This is raw string literals in C++11
Output
That is, the characters between the brackets will not be escaped and will be output as is.
Because "" is used frequently in regular expressions, this method avoids the problem of converting "" into "\".
For example:
If you don’t use this method, you need to write it like this:
The purpose of custom split string: identify where the raw string ends.