请教!怎么读取一个a文件的第5行内容,然后保存b文件中去

请问!!如何读取一个a文件的第5行内容,然后保存b文件中去。
小弟初学c语言,请教大家~~~~

------解决方案--------------------
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
string a;
string b;
cout < < "please input the input file name: " < < endl;
cin > > a;
cout < < "please input the output file name: " < < endl;
cin > > b;
ifstream fin(a.c_str());
if(!fin) {
cout < < "wrong input name! " < < endl;
exit(1);
}
ofstream fout(b.c_str());
if(!fout) {
cout < < "wrong output name! " < < endl;
exit(1);
}
string line;
for(int i=0;i <5;i++) {
if(!getline(fin, line)){
cout < < "sorry, not enough lines in " < < a < < endl;
exit(1);
}
}
fout < < line;
fin.close();
fout.close();
}
------解决方案--------------------
用 fgets 读取行即可:
#include <string.h>
#include <stdio.h>
int main()
{
FILE *filea, *fileb;
char string[256];
char a[20], b[20];
int index;

gets(a); //输入a文件名
gets(b); //输入b文件名
filea=fopen(a, "r ");
fileb=fopen(b, "w ");
for(index=0; index <5; index++) //读取第五行文件内容
fgets(string,256,filea);
fputs(string, fileb); //写到 b 文件中,OK

fclose(filea);
fclose(fileb);
return 0;
}
------解决方案--------------------
fgets(string,256,filea);
每读一次,就读一行

循环读到第五行