bit_xor的使用

今天遇到以一个bit_xor的情况,就是于是写了一个测试函数:

  1 #include      // std::cout
  2 #include 
  3 #include    // std::bit_xor
  4 #include     // std::accumulate
  5 #include      // std::end
  6 #include 
  7 int main () {
  8 std:: vectorflags;
  9         flags.push_back(2);
 10         flags.push_back(1);
 11         flags.push_back(2);
 12 
 13   int acc = accumulate (flags.begin(), flags.end(), 0,std::bit_xor());
 14   std::cout << "xor: " << acc << '\n';
 15   return 0;
 16 }
~                                                                               
~                                                                               
~                    

这个代码的意思 就是将二进制数字进行异或操作 然后取其和

你可能感兴趣的:(C++)