C++ で、独自の基本的な論理式エバリュエーターを作成しようとしていますが、String^ を std::string 値に変換する際に問題が発生しています。ここに私のコードのスニペットがあります:
String^ pattern = "[a-zA-Z ]+[>]+[ a-zA-Z]*" ;
Regex^ regex = gcnew Regex( pattern );
for( Match^ match = regex->Match( myExpression ); match->Success; match = match->NextMatch( ) )
{
if( match->Value->Length > 0 )
{
GetExpression(match->Value);
}
}
GetExpression() のプライベート メソッド定義は次のとおりです。
bool GetExpression(String^ matchedExpression)
{
--> std::string normalString = marshal_as<std::string>(matchedExpression);
std::vector<std::string> mystring = StringSplit(normalString, " ", false);
return true;
}
上記の行は、予期しない値を生成しています。"ax > bx" の文字列入力では、normalString に返される値は 7 の配列で、配列の最初の値は "!" です。そして残りは空です。途中のどこかで私が犯したエラーはありますか?myExpression は "ax > bx" の正しい値を持っているようです。前もって感謝します。