Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::vector<bool,Allocator>::flip

      From cppreference.com
      <cpp‎ |container‎ |vector bool
       
       
       
      std::vector<bool>
      Member types
      Member functions
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
      Helper classes
      Deduction guides(C++17)
       
      Defined in header<vector>
      void flip();
      (constexpr since C++20)

      Toggles eachbool (replaces with its opposite value) in thevector.

      [edit]Example

      Run this code
      #include <iostream>#include <vector> void print(conststd::vector<bool>& vb){for(constbool b: vb)std::cout<< b;std::cout<<'\n';} int main(){std::vector<bool> v{0,1,0,1};    print(v);    v.flip();    print(v);}

      Output:

      01011010

      [edit]See also

      access specified element
      (public member function ofstd::vector<T,Allocator>)[edit]
      toggles the values of bits
      (public member function ofstd::bitset<N>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/vector_bool/flip&oldid=178317"

      [8]ページ先頭

      ©2009-2026 Movatter.jp