求大神帮我解决
AMM.LHZ20060801000000.txt 的数据如下:
20060801000000 -46
20060801000001 -141
20060801000002 -171
20060801000003 -155
20060801000004 -53
20060801000005 -40
。。。。。。
问题是输出的文件多了一行数据,最后的两行数据重了。怎麽办?
/*对有时间的数据多次方*/
#include "iostream"
#include "iomanip"
#include "fstream"
#include"stdio.h"
#include"stdlib.h"
#include"cmath"
using namespace std;
int main()
{
ifstream ifile("AMM.LHZ20060801000000.txt");
ofstream ofile("pinfang.txt");
ofstream ofile2("temp.txt");
char buffer[30];
int numdate =15;//控制时间数字长度
char temp[8];
char result[100];
int i=0;
double y;
cout<<"输入n的值:"<<endl;
cin>>y;//改变次方数y
while(! ifile.eof())//改变控制条件,即可读取不同数据
{
ifile.getline (buffer,30,'\n');
int j=0;
for(;j<8;j++)
{
if(buffer[j+numdate] !='\n')
{
temp[j]=buffer[j+numdate];
}
else
{
temp[j+1]='\0';
break;
}
}
long p=0;
p=atol(temp);
p=pow(p,y);
sprintf(result,"%d",p);
ofile2<<temp<<endl;
ofile<<result;
if(!ifile.eof())
ofile<<endl;
}
ifile.close ();
ofile.close ();
return 0;
}