题
我有这个可变的dirpath2,其中我存储了路径的最深目录名称:
typedef std::basic_string<TCHAR> tstring;
tstring dirPath = destPath;
tstring dirpath2 = dirPath.substr(destPathLenght - 7,destPathLenght - 1);
我希望能够将其比较另一个字符串,类似:
if ( _tcscmp(dirpath2,failed) == 0 )
{
...
}
我尝试了很多事情,但似乎没有任何作用。谁能告诉我该怎么做,或者我在做什么错?
请记住,我几乎对C ++一无所知,这整个事情使我发疯。
提前
解决方案
std::basic_string<T>
超载 operator==
, , 尝试这个:
if (dirpath2 == failed)
{
...
}
另外,您可以这样做。作为 std::basic_string<T>
没有隐性转换操作员 const T*
, ,您需要使用 c_str
成员功能转换为 const T*
:
if ( _tcscmp(dirpath2.c_str(), failed.c_str()) == 0 )
{
...
}
其他提示
STD :: BASIC_STRING具有a ==运算符。使用字符串类模板:
if (dirpath2 == failed)
{
...
}
不隶属于 StackOverflow