一个程序 c++

来源:百度知道 编辑:UC知道 时间:2024/07/01 15:29:09
#include "stdafx.h"
#include "fstream"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
char a[2];
ifstream fin("in.txt");
ofstream fout("out.txt");
if(fin==NULL)
{
cout<<"can't open fin"<<endl;
return 0;
}
if(fout==NULL)
{
cout<<"can't open fout"<<endl;
return 0;
}
while(fin.get(a[0]))
{
fout.put(a[0]);
fin.get(a[0]);
fin.get(a[0]);
fin.seekg(-2,ios::cur);
}
fin.close();
fout.close();
return 0;
}
in.txt 输入 “大”和“回车”out.txt会有什么结果?还有我把倒数第五行改成fin.seekg(-1,ios::cur);fin.seekg(-1,ios::cur);为什么就死循环了?
算了,只要说为什么改了就死循环就行了

要想读入中文,就不要用char,要用到宽字符类型,具体根据编译器来。
如果非要用char来读中文字符,那么就会逐个字节逐个字节地读取,显示出来就是不可认识的字符

您好char是可以使用的,
但是您输入中文的时候要注意不能把char型字符串数组打散
让它两两成组 是不可以出现a[0]的