向文件中输入汉字

#include<iostream>
#include<fstream>

using namespace std;

int main()
{
char a[]="Hello I am 黄景天.你好,你是谁啊?";
ofstream of("E://text.txt");
if(of==NULL)
{
cerr<<"The file was not opened."<<endl;
exit(1);
}


int len=strlen(a);
unsigned char *p=(unsigned char *)a;
while(*p)
{
if(*p<128)
{
of.write((char *)p,sizeof(char));
p=p+1;

}
else
{
of.write((char *)p,sizeof(char));
of.write((char *)&p[1],sizeof(char));
p+=2;

}
}
cout<<"succssful."<<endl;

system("pause");
return 0;
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页