如何用C++在文本文件中输出二进制数?

来源:百度知道 编辑:UC知道 时间:2024/09/23 21:18:30

#include <bitset>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string str = "abcde123";
char ch;
fstream f;
f.open("d:\\test.txt");
for (int i = 0, ch = str[0];ch != '\0'; i++)
{
ch = str[i];
bitset<32> se(ch);
f << se;
}

f.close();
}

FILE * fp;
fp = fopen("c:\\test.dat", "wb");
fputc(fp, ch);
fclose(fp);

#include <iostream>
#include <vector>
using namespace std;
class node
{public:
long a;
};
main()
{node *head;
vector<char>V(0);
vector<char>::iterator psdz;
head=new node;
cout<<"输入数字";
cin.setf(ios::dec,ios::basefield);
cin>>head->a;
cout<<"输出八进制:";
cout.setf(io