C++文本输出和控制台的换行问题补充

#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
struct Student
{
int textnumber;
string name;
int chinese;
int math;
int english;
};
int Sum(int a,int b,int c){return a+b+c;}
int main()
{
Student stu;
char a[50];
int sum;
cout<<"请输入收到的汇总表的文件名(含该文件的路径和后缀名,若与本程序同一文件夹可省略路径)"<<endl;
cin>>a;
ifstream infile(a,ios::binary);
ofstream outfile("student.txt",ios::binary|ios::app);
if(!infile||!outfile)
{
cout<<"文件打开失败!"<<endl;
return 1;
}
outfile<<setw(8)<<"考号"<<setw(8)<<"姓名"<<setw(8)<<"语文"<<setw(8)<<"数学"<<setw(8)<<"英语"<<endl;
while(!infile.eof())
{
infile>>stu.textnumber>>stu.name>>stu.chinese>>stu.math>>stu.english;
sum=Sum(stu.chinese,stu.math,stu.english);
outfile<<setw(8)<<stu.textnumber<<setw(8)<<stu.name<<setw(8);
outfile<<stu.chinese<<setw(8)<<stu.math<<setw(8)<<stu.english<<setw(8)<<sum<<endl;
cout<<setw(8)<<stu.textnumber<<setw(8)<<stu.name<<setw(8);
cout<<stu.chinese<<setw(8)<<stu.math<<setw(8)<<stu.english<<setw(8)<<sum<<endl;
}
infile.close();
outfile.close();
return 0;
}

文本是这个:

10000101 张海 90 88 115
10002932 刘强 101 99 110

为什么控制台能换行,文本里几换不了
哪里出问题了?
已经知道问题出哪里了 第一个回复的人就给满意吧

楼主你真有雅兴。
答:因为你是用binary方式打开的。
用binary方式打开的文件,对整数居然也可以用>>操作符。这点倒没想到。不过对二进制文件一般不会用>>和<<的吧。
温馨提示:答案为网友推荐,仅供参考
相似回答