mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 01:54:36 +03:00
Added raw string literals to C++11 features (#96)
* Added raw string literals to C++11
This commit is contained in:
22
CPP11.md
22
CPP11.md
@@ -35,6 +35,7 @@ C++11 includes the following new language features:
|
||||
- [trailing return types](#trailing-return-types)
|
||||
- [noexcept specifier](#noexcept-specifier)
|
||||
- [char32_t and char16_t](#char32_t-and-char16_t)
|
||||
- [raw string literals](#raw-string-literals)
|
||||
|
||||
C++11 includes the following new library features:
|
||||
- [std::move](#stdmove)
|
||||
@@ -696,6 +697,27 @@ char32_t utf8_str[] = U"\u0123";
|
||||
char16_t utf8_str[] = u"\u0123";
|
||||
```
|
||||
|
||||
### Raw string literals
|
||||
C++11 introduces a new way to declare string literals as "raw string literals". Characters issued from an escape sequence (tabs, line feeds, single backslashes, etc.) can be inputted raw while preserving formatting. This is useful, for example, to write literary text, which might contain a lot of quotes or special formatting. This can make your string literals easier to read and maintain.
|
||||
|
||||
A raw string literal is declared using the following syntax:
|
||||
```
|
||||
R"delimiter(raw_characters)delimiter"
|
||||
```
|
||||
where:
|
||||
* `delimiter` is an optional sequence of characters made of any source character except parentheses, backslashes and spaces.
|
||||
* `raw_characters` is any raw character sequence; must not contain the closing sequence `")delimiter"`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
// msg1 and msg2 are equivalent.
|
||||
const char* msg1 = "\nHello,\n\tworld!\n";
|
||||
const char* msg2 = R"(
|
||||
Hello,
|
||||
world!
|
||||
)";
|
||||
```
|
||||
|
||||
## C++11 Library Features
|
||||
|
||||
### std::move
|
||||
|
||||
22
README.md
22
README.md
@@ -108,6 +108,7 @@ C++11 includes the following new language features:
|
||||
- [trailing return types](#trailing-return-types)
|
||||
- [noexcept specifier](#noexcept-specifier)
|
||||
- [char32_t and char16_t](#char32_t-and-char16_t)
|
||||
- [raw string literals](#raw-string-literals)
|
||||
|
||||
C++11 includes the following new library features:
|
||||
- [std::move](#stdmove)
|
||||
@@ -1932,6 +1933,27 @@ char32_t utf8_str[] = U"\u0123";
|
||||
char16_t utf8_str[] = u"\u0123";
|
||||
```
|
||||
|
||||
### Raw string literals
|
||||
C++11 introduces a new way to declare string literals as "raw string literals". Characters issued from an escape sequence (tabs, line feeds, single backslashes, etc.) can be inputted raw while preserving formatting. This is useful, for example, to write literary text, which might contain a lot of quotes or special formatting. This can make your string literals easier to read and maintain.
|
||||
|
||||
A raw string literal is declared using the following syntax:
|
||||
```
|
||||
R"delimiter(raw_characters)delimiter"
|
||||
```
|
||||
where:
|
||||
* `delimiter` is an optional sequence of characters made of any source character except parentheses, backslashes and spaces.
|
||||
* `raw_characters` is any raw character sequence; must not contain the closing sequence `")delimiter"`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
// msg1 and msg2 are equivalent.
|
||||
const char* msg1 = "\nHello,\n\tworld!\n";
|
||||
const char* msg2 = R"(
|
||||
Hello,
|
||||
world!
|
||||
)";
|
||||
```
|
||||
|
||||
## C++11 Library Features
|
||||
|
||||
### std::move
|
||||
|
||||
Reference in New Issue
Block a user