我使用以下代码在C ++中读取文本文件:
void main()
{
clrscr();
ifstream o("file.txt",ios::in);
while(!o.eof())
{
o.get(w);
cout<<w;
}
getch();
}
但输出显示文件中各个字母之间的空格,
虽然原始文件中没有这样的空格。
示例:如果文件包含hello
,则我的输出会显示h e l l o
。
如何纠正?
答案 0 :(得分:0)
试试这个
while (o>>w) cout<<w;
因为你正在处理unicode,所以char不会解决问题。尝试使用 wchar_t的。