Advantages of using user-defined literal for strings instead of string literal

后端 未结 4 1499
野趣味
野趣味 2020-12-29 17:34

The strings topic in the SO Documentation used to say, in the Remarks section:

Since C++14, instead of using \"foo\", it is recommended t

4条回答
  •  無奈伤痛
    2020-12-29 18:10

    1. Using a C++ string literal means we do not need to call strlen to compute the length. The compiler already knows it.
    2. Might allow library implemetations where the string data points to memory in global space will using C literals must always force a copy of the data to heap memory on construction.

提交回复
热议问题