第1个回答 2011-01-20
可以用string来读取中文
#include"fstream"
#include"string"
using namespace std;
int main()
{
string s;
ifstream fin;
ofstream fout;
fin.open("F:\\1.txt");
fout.open("F:\\1.xls");
while(!fin.eof())
{
getline(fin,s); //读取一行字符,要求一行字符中没有制表符'\t',否则用本程序实现不了把一行字符输出到一格excle中
fout<<s<<'\n'; //输出字符,如果不想换行,就去掉'\n'
}
fin.close();
fout.close();
system("pause");
return 0;
}
第2个回答 2011-01-20
{
FILE *fp;
char buf[1000];
fp=fopen("student.txt","r");
if(!fp)
{
printf("打开文件出错\n");
return;
}
while(fscanf(fp,"%s",buf))>0)
{
..................................
}
fclose(fp);
}
这样就能每次读取一行字符串
第3个回答 2011-01-20
试试将txt文件另存为unicode编码。。。
第4个回答 推荐于2017-10-11
vs2008 、vs2005下 std::ifstream中不支持中文,是因为在vs2008 、vs2005 下,默认传入的 unicode 字符集 ,而一般开发的时候 大多数使用的多字节字符集,所以会导致出错 。
1、使用C语言的函数设置为中文运行环境
setlocale(LC_ALL, "Chinese-simplified");
2、使用STL函数设置为系统语言环境
std::locale::global(std::locale(""));
3. 或者 直接 修改 log4cpp 的 参数,直接传入的是 宽字节 。