File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
reference/string_view/basic_string_view Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -45,8 +45,18 @@ inline namespace string_view_literals {
4545
4646## 備考
4747- 中間にヌル文字を含む文字列リテラルから`basic_string_view`オブジェクトを構築する場合、コンストラクタを使用するよりもこちらの関数を使用したほうがよい。
48- - `const char*`をとるコンストラクタは[`std::char_traits`](/reference/string/char_traits.md)`::`[`length()`](/reference/string/char_traits/length.md)関数を使用して文字列長を計算するため、ヌル終端となってしまう
48+ - `const char*`をとるコンストラクタは[`std::char_traits`](/reference/string/char_traits.md)`::`[`length()`](/reference/string/char_traits/length.md)関数を使用して文字列長を計算するため、ヌル終端までの長さとなる。そのコンストラクタでは文字列の途中にヌル文字がある場合、文字列の終端まで扱われないので注意が必要となる
4949 - こちらの関数は文字列リテラルの長さを直接扱うため、文字列全体を参照する`basic_string_view`オブジェクトを構築できる
50+ ```cpp
51+ // コンストラクタは、ヌル文字までの長さ
52+ const char* s = "123\0abc";
53+ auto sv0 = std::string_view{s};
54+ assert(sv0.length() == 3); // "123"
55+
56+ // svリテラルは全体の長さ
57+ auto sv1 = "123\0abc"sv;
58+ assert(sv1.length() == 7); // "123\0abc"
59+ ```
5060
5161
5262## 例
You can’t perform that action at this time.
0 commit comments