Skip to content

Commit 17f4bc1

Browse files
authored
Added raw string literals to C++11 features (AnthonyCalandra#96)
* Added raw string literals to C++11
1 parent d9b9989 commit 17f4bc1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

CPP11.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ C++11 includes the following new language features:
3535
- [trailing return types](#trailing-return-types)
3636
- [noexcept specifier](#noexcept-specifier)
3737
- [char32_t and char16_t](#char32_t-and-char16_t)
38+
- [raw string literals](#raw-string-literals)
3839

3940
C++11 includes the following new library features:
4041
- [std::move](#stdmove)
@@ -696,6 +697,27 @@ char32_t utf8_str[] = U"\u0123";
696697
char16_t utf8_str[] = u"\u0123";
697698
```
698699

700+
### Raw string literals
701+
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.
702+
703+
A raw string literal is declared using the following syntax:
704+
```
705+
R"delimiter(raw_characters)delimiter"
706+
```
707+
where:
708+
* `delimiter` is an optional sequence of characters made of any source character except parentheses, backslashes and spaces.
709+
* `raw_characters` is any raw character sequence; must not contain the closing sequence `")delimiter"`.
710+
711+
Example:
712+
```cpp
713+
// msg1 and msg2 are equivalent.
714+
const char* msg1 = "\nHello,\n\tworld!\n";
715+
const char* msg2 = R"(
716+
Hello,
717+
world!
718+
)";
719+
```
720+
699721
## C++11 Library Features
700722

701723
### std::move

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ C++11 includes the following new language features:
108108
- [trailing return types](#trailing-return-types)
109109
- [noexcept specifier](#noexcept-specifier)
110110
- [char32_t and char16_t](#char32_t-and-char16_t)
111+
- [raw string literals](#raw-string-literals)
111112

112113
C++11 includes the following new library features:
113114
- [std::move](#stdmove)
@@ -1932,6 +1933,27 @@ char32_t utf8_str[] = U"\u0123";
19321933
char16_t utf8_str[] = u"\u0123";
19331934
```
19341935

1936+
### Raw string literals
1937+
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.
1938+
1939+
A raw string literal is declared using the following syntax:
1940+
```
1941+
R"delimiter(raw_characters)delimiter"
1942+
```
1943+
where:
1944+
* `delimiter` is an optional sequence of characters made of any source character except parentheses, backslashes and spaces.
1945+
* `raw_characters` is any raw character sequence; must not contain the closing sequence `")delimiter"`.
1946+
1947+
Example:
1948+
```cpp
1949+
// msg1 and msg2 are equivalent.
1950+
const char* msg1 = "\nHello,\n\tworld!\n";
1951+
const char* msg2 = R"(
1952+
Hello,
1953+
world!
1954+
)";
1955+
```
1956+
19351957
## C++11 Library Features
19361958

19371959
### std::move

0 commit comments

Comments
 (0)