# azure active directory – how can i slice a V_BSTR in c++?

Use std::wstring to pull apart the BSTR after copying. one way of doing this is below

ATL::CComVariant var;
hr = pUsr->Get(ATL::CComBSTR("userAccountControl"), &var);
if (SUCCEEDED(hr) && V_VT(&var) == VT_BSTR)
{
std::wstring wstr = V_BSTR(&var);
if (wstr.length() >= 3)
wstr = wstr.substr(wstr.length()-3);

// convert to integer.
int res = std::stoi(wstr);

// TODO: do something with 'res'
std::cout << res << '\n'
}


That said, clearly you’re calling this code from some context neither shown, nor really discussed, in your post. But this is one way to do what you want, and has no memory leaks as a bonus.