字符串转换问题
怎么把字符串转换成2进制代码?例如吧A转换成1000100,要求对汉字也可以哦。而且是一大串字符转换。本人使用的是vc++6.0编译器。
2012-03-09 18:45
程序代码:#include <string>
#include <iostream>
using namespace std;
int main() {
string str;
char ch;
cin >> str;
string::iterator iter = str.begin();
while (iter != str.end()) {
ch = *iter++;
for (int i = 0; i < 8; ++i)
cout << ((ch >> i) & 1);
}
}

2012-03-09 20:11
程序代码: string::iterator iter = str.begin();
while (iter != str.end()) {
ch = *iter++;
for (int i = 0; i < 8; ++i)
cout << ((ch >> i) & 1);
}
这部分能不能给些注释?
2012-03-09 23:39

2012-03-10 10:40
2012-03-10 13:12
2012-03-10 14:02
2012-03-10 19:24
程序代码:#include <string>
#include <iostream>
using namespace std;
int main()
{
string str;
FILE *fp;
char ch;
if((fp=fopen("file.txt","wb+"))==NULL)
{
cout<<"can not open this file.\n";
return 0;
}
cin >> str;
string::iterator iter = str.begin();
while (iter != str.end()) {
ch = *iter++;
for (int i = 0; i < 8; ++i)
fputc(((ch >> i) & 1),fp);
}
fclose(fp);
}
要怎么改才能吧那些2进制码写到想要的文件中呢?
2012-03-17 13:38

2012-03-17 15:58
2012-03-17 23:43