std::string に条件付きブレークポイントを設定するには、std::string の実際の内部メンバーに設定する必要があります。ウォッチ ウィンドウに表示される内容は簡略化されています。
,!
サフィックスを使用して、ウォッチ ウィンドウに変数の実際の構造を表示できます。あなたの例では:
newString,!
MSVC 2015 – 2019 の場合、次を使用できます。
15 文字を超えない文字列の場合:
(newString._Mypair._Myval2._Myres < 16) ?
strcmp(newString._Mypair._Myval2._Bx._Buf, "short") == 0 :
false
(歴史的にも) 長い文字列の場合:
(newString._Mypair._Myval2._Myres < 16) ? false :
strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_str_value_longer_than_16_chars") == 0
注意:
- 条件ごとに変数名が2回書かれています!
- 単一行で式全体が必要です。以下のコピペバージョンを使用してください。
ユニバーサル条件では、テスト値を 2 回、変数名を 3 回入力する必要があります。
(newString._Mypair._Myval2._Myres < 16) ?
strcmp(newString._Mypair._Myval2._Bx._Buf, "My_test_string") == 0 :
strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_string") == 0
注: を使用している場合は、wcscmp
代わりに を使用してください。strcmp
std::wstring
C++ での小さな文字列の最適化に関する詳細情報を参照してください https://vorbrodt.blog/2019/03/30/sso-of-stdstring/には、文字列の内部バッファーのサイズを見つけるためのサンプル コードが含まれています。
すべての std:string および std::wstring 単一行バージョンは、コピーと貼り付けに便利です。
(newString._Mypair._Myval2._Myres < 16) ? strcmp(newString._Mypair._Myval2._Bx._Buf, "short") == 0 : false
(newString._Mypair._Myval2._Myres < 16) ? false : strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_str_value_longer_than_16_chars") == 0
(newString._Mypair._Myval2._Myres < 16) ? strcmp(newString._Mypair._Myval2._Bx._Buf, "My_test_string") == 0 : strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_string") == 0
(newString._Mypair._Myval2._Myres < 16) ? wcscmp(newString._Mypair._Myval2._Bx._Buf, L"short") == 0 : false
(newString._Mypair._Myval2._Myres < 16) ? false : wcscmp(newString._Mypair._Myval2._Bx._Ptr, L"My_test_str_value_longer_than_16_chars") == 0
(newString._Mypair._Myval2._Myres < 16) ? wcscmp(newString._Mypair._Myval2._Bx._Buf, L"My_test_string") == 0 : wcscmp(newString._Mypair._Myval2._Bx._Ptr, L"My_test_string") == 0
上記のすべてのコピー/貼り付けサンプルは、MSVC バージョン 16.9.10 および Windows 10 用のプログラムでテストされています。