向文件中输入汉字

    技术2022-05-11  98

    #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; }


    最新回复(0)