奇怪的 wstring.find() 行为 | VS C++ 最新

Weird wstring.find() behavior | VS C++ Latest

std::wstring buf;

if (buf.find(L"Josh") != std::wstring::npos && !buf.find(L"NotJosh") != std::wstring::npos)
{
    // I'm trying to find a specific wstring that contains "Josh" but not "NotJosh" 
    // yet the .find() func returns positive even if it finds "NotJosh"
    // even tho it's conditions is set to (!)
}

/// This one doesn't work either:

if (!buf.find(L"NotJosh") != std::wstring::npos)
{
    if (buf.find(L"Josh") != std::wstring::npos)
    {

    }
}

@Jesper 解决的问题:

This looks fishy: !buf.find(L"NotJosh") != std::wstring::npos Why not just: buf.find(L"NotJosh") == std::wstring::npos

还有@NathanOliver:

! has higher precedence then != so !buf.find(L"NotJosh") != std::wstring::npos should be !(buf.find(L"NotJosh") != std::wstring::npos)

谢谢大家