How to set all bits of bitset to 1 in C++

1 Answer

0 votes
#include <iostream>
#include <bitset> 

using std::cout;
using std::endl;

int main()
{
	std::bitset<4> bs; // 0000
	bs.set();          // 1111

	std::string s =
		bs.to_string<char, std::string::traits_type, std::string::allocator_type>();

	cout << s << endl;

	return 0;
}


/*
run:

1111

*/

 



answered Jul 16, 2018 by avibootz

Related questions

1 answer 194 views
194 views asked Jul 17, 2018 by avibootz
1 answer 159 views
1 answer 202 views
1 answer 167 views
1 answer 202 views
1 answer 205 views
...