检查字符串值时"error: no match for operator=="
"error: no match for operator==" when checking the value of a string
如何检查字符串是否等于'♦'?
将some_string设置为4并打印如下:
some_string = 4;
cout << some_string;
给我看这个:
♦
但是我该怎么测试呢?我试过了,但不起作用:
if (some_string==4){
}
谢谢!
编辑:
如果您想测试字符代码为4的字符,那么您可以执行以下操作:
if(some_string == 'x04') {
//Do something...
}
字符串以字符的形式进行输入。。
string some_string="4 ";
初始化字符串时总是使用"\0",也就是以NULL结尾的字符,因为它告诉字符串已经结束,否则程序将继续检查内存中的下一个连续位置,这将导致错误。
您可以使用关系运算符。。
if(some_string=="some_value")
{
//Do Something....
}
相关文章:
- 错误消息:使用"string* +="后"no match for 'operator+='"
- 在 Eclipse: "error: no match for 'operator='" 中获取错误消息
- 如何'Invalid conversion'和'no match for operator'更正这些 c++ 错误
- 为什么当我没有变量或其他任何命名的东西时"no match for 'operator==' "错误?
- 为什么我收到以下错误:"no match for 'operator=='"?(带模板的嵌套类)
- 在命名空间内的类中使用带有运算符重载的字符串流时"no match for ‘operator>>’"
- 如何修复C++中的"no match for operator+"?
- 运算符重载错误"no match for operator error"
- "No match for operator []"
- 如果我没有重载,为什么我会"no match for ‘operator=’"自定义类?
- 为什么编译器显示错误"no match for 'operator[]' (operand types are 'carti' and 'int')"
- 对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
- "no match for 'operator >>'"代码中是什么意思?
- "no match for ‘operator>>’ in ‘inputFile >> buffer"错误?
- 如何修复" no match for 'operator<<' in 'std::cout"错误?
- 简单迭代器差异的"No match for operator-"错误
- 使用 std::string 时"error: no match for ‘operator<<"
- 访问基于遗传算法的PNRG中的数组? " no match for operator[] "
- "No match for operator+"
- C++ 遍历 3D 数组'no match for operator='