输出是乱码的问题。
#include "stdafx.h"
#include <fstream>
#include <iomanip>
#include<string>
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
ifstream file; ofstream fil2;
int i=0,j=0,total_number=0,p=0,q=0;
char str[1000],str2[1000],str3[1000];
memset(str,0,1000);memset(str2,0,1000);memset(str3,0,1000);
char cell;
file.open("word.txt");
cell=file.get();
while(cell!=EOF)
{
str[i]=cell;
cell=file.get();
i++;
} total_number=i;
for(i=0;i<total_number;i++)
str2[j++]=str[j];
for(i=0;i<total_number;i=i+2)
{
for(j=0;j<total_number;j=j+2)
if(str[i]==str2[j]&&str[i+1]==str2[j+1])
p++;
if(p<2)
{ str3[q++]=str[i];str3[q++]=str[i+1]; }
p=0;
}
ofstream file2; file2.open("word_result.txt");
for( j=0; j<q; j++)
cout<<str3[j];
file2.write (str3,q);
file.close();
file2.close();
return 0;
}
这个程序在
for( j=0; j<q; j++)
cout<<str3[j];
可以正常输出,但写入文件时就是乱码,不知道为什么?
高手们帮忙啊
问题点数:20、回复次数:1Top
1 楼sad_4978(回忆之前,忘记之后)回复于 2006-07-07 11:07:06 得分 0
在创建文件的时候使用UTF-8编码格式。
最好使用UNICODE字符。Top




