C++ STL vector_bool, flip() code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Using the C++ flip() to reverse all bits in the vector in C++ programming

To show: How to use the C++ vector_bool, flip() to reverse all bits in the vector in C++ programming

 

// C++ STL vector_bool, flip()

#include <vector>

#include <iostream>

using namespace std;

 

int main(void)

{

// bool vector

_Bvector vecbool;

 

// push data

vecbool.push_back(1);

vecbool.push_back(0);

 

// print the data and do some operations

cout<<"The vecbool vector is: "<<vecbool.front()<<" "<<vecbool.back()<<endl;

cout<<"\nOperation: vecbool.flip();"<<endl;

vecbool.flip();

cout<<"The flipped vecbool vector is: "<<vecbool.front()<<" "<<vecbool.back()<<endl;

return 0;

}

 

Output examples:

 

The vecbool vector is: 1 0

Operation: vecbool.flip();

The flipped vecbool vector is: 0 1

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index