响应式的网站建设一个多少钱,成都优化官网推广,tag改为静态wordpress,360网站名片怎么做的在C11中添加了定义原始字符串的字面量#xff0c;定义方式为#xff1a;R “xxx(原始字符串)xxx”其中#xff08;#xff09;两边的字符串可以省略。原始字面量R可以直接表示字符串的实际含义#xff0c;而不需要额外对字符串做转义或连接等操作。 编程过程中#xff0c…在C11中添加了定义原始字符串的字面量定义方式为R “xxx(原始字符串)xxx”其中两边的字符串可以省略。原始字面量R可以直接表示字符串的实际含义而不需要额外对字符串做转义或连接等操作。 编程过程中使用的字符串中常带有一些特殊字符对于这些字符往往要做专门的处理使用了原始字面量就可以轻松的解决这个问题了比如打印路径
#includeiostream
#includestring
using namespace std;
int main()
{string str D:\hello\world\test.text;cout str endl;string str1 D:\\hello\\world\\test.text;cout str1 endl;/**************新特性**************/string str2 R(D:\hello\world\test.text); cout str2 endl;return 0;
}在R(D:\hello\world\test.text)使用了原始字面量R中的内容就是描述路径的原始字符串无需做任何处理. 再看一个输出HTML标签的例子
#includeiostream
#includestring
using namespace std;
int main()
{
#if 0string str html\head\title\海贼王\/title\/head\body\p\我是要成为海贼王的男人!!!\/p\/body\/html;cout str endl;
#else if //新特性string str R(htmlheadtitle海贼王/title/headbodyp我是要成为海贼王的男人!!!/p/body/html);cout str endl;
#endifreturn 0;
}最后强调一个细节在R “xxx(raw string)xxx” 中原始字符串必须用括号括起来括号的前后可以加其他字符串所加的字符串会被忽略并且加的字符串必须在括号两边同时出现。
#includeiostream
#includestring
using namespace std;
int main()
{string str1 R(D:\hello\world\test.text);cout str1 endl;string str2 Rluffy(D:\hello\world\test.text)luffy;cout str2 endl;
#if 0string str3 Rluffy(D:\hello\world\test.text)robin; // 语法错误编译不通过cout str3 endl;
#endifreturn 0;
}通过输出的信息可以得到如下结论使用原始字面量R “xxx(raw string)xxx”两边的字符串在解析的时候是会被忽略的因此一般不用指定。如果在前后指定了字符串那么前后的字符串必须相同否则会出现语法错误。