C2296:' - ':非法,左操作数的类型为'unsigned int

时间:2014-02-09 12:09:42

标签: c++ string

当我尝试从另一个子字符串中提取子字符串时,会发生此错误。我认为它来自我正在尝试制作的这个操作strApp.length - 2,但我找不到如何修复它。

错误讯息:

  

C2296:' - ':非法,左操作数的类型为'unsigned int(__thiscall   的std :: basic_string的,性病::分配器> :: *   )(void)throw()

相关代码:

this->appName = strApp.substr(strApp.substr(0, strApp.length - 2).find_last_of("\\") + 1, strApp.length);

有什么好的建议吗?

1 个答案:

答案 0 :(得分:3)

假设strAppstd::stringlength成员是一个函数,所以你需要调用它来获取字符串的长度。要调用函数,必须在函数名称后面加上括号:

strApp.length()

由于length函数不带任何参数,因此括号为空。

相关问题