C++编程read data from a file

来源:百度知道 编辑:UC知道 时间:2024/05/15 08:06:04
各位帮个忙拉
从a file中read下面的data,帮我便一个C++ program

student name:A student ID:********

Semester I:
Course code Mark Credit
SCK1213 81 3
SCK1023 80 3
SCK1413 99 3
SSM1173 96 3
UHS1152 98 2
UHS1412 74 2

Semester II:
Course code Mark Credit
SCK1223 80 3
SCK2423 89 3
SCK1013 81 3
SCK1813 67 3
SCK2823 90 3
ULT1022 79 2
UQRXXXX1 86 1

student name:B student ID:********

Semester I:
Course code Mark Credit
SCK1213 81 3
SCK1023 80 3
SCK1413 99 3
SSM117

#include<fstream.h>
#include<stdlib.h>
void main ()
{
char infilename[256],buff[256];
cout<<"请输入源文件:";
cin>>infilename;
fstream infile;
infile.open(infilename,ios::in|ios::noreplace|ios::nocreate);
if(!infile)
{
cout<<"不能打开源文件 "<<infilename<<'\n';
exit(1);
}
while(!infile.eof ())
{
infile.read (buff,256);
cerr<<buff<<endl;
}
infile.close ();

}