1

在 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”的正确值。提前致谢。

4

0 回答 0