首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

如何把读出来的数据输入txt

2012-03-01 
怎么把读出来的数据输入txt我想把读出来的数据全部写到txt上去,怎么实现呢?我写的不行#includestdafx.h

怎么把读出来的数据输入txt
我想把读出来的数据全部写到txt上去,怎么实现呢?我写的不行

#include   "stdafx.h "
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <math.h>
void   main()
{
char   curve_id[15];
char   str[256];
int   pulse,i;
        double   index,   vps,wid;
int   loss_rate;
int   point_num;
unsigned   short   *pData;
FILE   *fp=fopen( "c:\\trace04.dat ", "rb ");
//FILE   *fp=fopen( "C:\\Program   Files\\Microsoft   Visual   Studio\\MyProjects\\读数据\\trace01.dat ", "rb ");
if(fp==NULL)
{
cout < < "not   exist " < <endl;
}
fread(curve_id,1,14,fp);
fread(str,1,6,fp);
str[6]=0;
pulse=atoi(str);
fread(str,1,6,fp);
loss_rate=atoi(str);
fread(str,1,6,fp);
index=atof(str);
fread(str,1,6,fp);
vps=atof(str);
fread(str,1,6,fp);
point_num=atoi(str);
pData=new   unsigned   short[point_num];
        fread(pData,2,point_num,fp);
for(i=0;i <point_num;i++)
        {
cout < < "[ " < <i < < "]= " < <pData[i] < < "   ";
}
cout < < "pulse= " < <pulse < <endl;
cout < < "loss_rate= " < <loss_rate < <endl;
cout < < "index= " < <index < <endl;
cout < < "point_num= " < <point_num < <endl;
cout < < "vps= " < <vps < <endl;
wid=0.1*pulse/vps;
cout < < "wid= " < <wid < <endl;
ofstream   tfile( "shuju.txt ",ios::binary);
tfile.write((char*)&pData[i],sizeof   pData[i]);
}


[解决办法]
ofstream tfile( "shuju.txt ",ios::app);
tfile < < pData;

热点排行