错误:类型&#39; int&#39;的操作数无效和&#39; <unresolved overloaded =“”function =“”type =“”>&#39;到二进制&#39;运算符&lt;&lt;&lt;&#39; </unresolved>

时间:2014-07-10 07:17:37

标签: c++

我想获得z_Data

的第48个字符的第6位
{
    char c = pPkt->z_Data[47];                // this z_Data is a char buffer
    std::cout<<(c>>3)&1<<std::endl;
    std::cout<<(c>>4)&1<<std::endl;
    std::cout<<(c>>5)&1<<std::endl;
}

1 个答案:

答案 0 :(得分:8)

<<的优先级高于&的优先级,因此您需要:

std::cout << ((c >> 3) & 1) << std::endl;
std::cout << ((c >> 4) & 1) << std::endl;
std::cout << ((c >> 5) & 1) << std::endl;