如何通过C++程序把word文档的内容变成乱码

来源:百度知道 编辑:UC知道 时间:2024/05/11 02:40:23

用一个没有初始化的字符串写入文件就行了

#include<iostream>

using namespace std;

int main()
{
FILE *fp;
char str[10000];
if((fp=fopen("c:\\1.doc","w"))==NULL)
{
cout<<"can't open the file"<<endl;
exit(0);
}
fprintf(fp,"%s",str);
fclose(fp);
return 0;
}

可以采用加密:
m=128-m;(m 为原码)
这样实现:
#include <iostream.h>
#include <stdio.h>
int main()
{
FILE *fp1=fopen("kkk.doc","r");
if(!fp1){cout<<"bad";return 1;}
FILE *fp2=fopen("kkk.doc","w");
if(!fp2){cout<<"bad";return 1;}
char t;
while(t!=EOF)
{
t=fgetc(fp1);
t=128-t;
fputc(t,fp2);
}
fclose(fp1);
fclose(fp2);
return 0;
}