C语言表达字符串时很多字符都需要转义符, 比如:
const char* s2 = " Hello World ";
打印出来就是
Hello World
如果想打印
Hello
World
就必须这么写:
const char* s2 = "\nHello\nWorld\n";
如果字符串比较短, 手工添加转义符工作量不大, 但是如果字符串比较长, 手工添加转义符就很繁重, 尤其是网络编程, 经常要发送大段的字符串, 比如:
<html> <head> <title>XMC4700/XMC4800 RelaxKit Web Server</title> </head> <body> <script> function change1(){ top.frames.ifr.location.href="./led1.html?LED1=OnOff"; } function change3(){ top.frames.ifr.location.href="./dts.html?DTS=Console"; } </script> <div align=center> <p font=16>XMC4700 RelxKit Web Server Demo</p> <p>Press button to control board</p> <p/><a href="404.htm"><img src="img_sis.gif"></img></a> <button type="button" onclick="change1()">Switch LED1 </button> <button type="button" onclick="change3()">Die Temperature</button> <iframe id="ifr" name="ifr" frameborder="0" scrolling="no" width="0" height="0"></iframe> </div> </body> </html>
如果要添加手工添加转义符, 工作量很大. 这时候如果用C++的raw string可以大大简化代码工作, 注意, 这个特性需要C++11之后的标准才支持.
只有注册用户才能在此添加评论。 如果您已经注册,请登录。 如果您还没有注册,请注册并登录。