Try:
#include
#include
int main() {
using namespace std;
const bitset<12> x(2730ul);
cout << "x = " << x << endl;
ofstream ofs("C:\\test.txt"); // write as txt
if (ofs) {
// easy way, use the stream insertion operator
ofs << x << endl;
// using fstream::write()
string s = x.to_string();
ofs.write(s.c_str(), s.length());
}
return 0;
}