#include <fstream>
const int CHANEL_LEN = 1024;
int m_ArrData[CHANEL_LEN];
string strFile = "c:\\aaa.dat";
ofstream outfile(strFile.c_str()); //写入文件
int time = 135102989;
int g_iCollectTime = 50,g_iCollectJishu = 100,m_iSecsCurrTm = 200,iKeduXishu = 300;
outfile << time << " " << g_iCollectTime << " " << m_iSecsCurrTm << " " << iKeduXishu << " ";
for (int i = 0;i < CHANEL_LEN;++i)
{
m_ArrData[i] = i;
}
for (int i = 0;i < CHANEL_LEN;++i)
{
outfile << m_ArrData[i] << " ";
}
outfile.close();
time = -1;g_iCollectTime = -1;m_iSecsCurrTm = -1; iKeduXishu = -1;
ifstream infile(strFile.c_str()); //写入文件
int iValue = 0,iMax = -1;
int iTemp;
//outfile << tmCurrent.GetTime() << " " << g_iCollectTime << " " << m_iSecsCurrTm << " " << iKeshuXishu << " ";
infile >> time >> g_iCollectTime >> m_iSecsCurrTm >> iKeduXishu;
memset(m_ArrData,0,sizeof(m_ArrData));
int i = 0;
for (i = 0;i < CHANEL_LEN && !infile.eof() ;++i)
{
if(iMax < iValue) iMax = iValue;
infile >> iValue;
m_ArrData[i] = iValue;
g_iCollectJishu += iValue;
}
infile.close();
一个简单的std 读写简单数据的文件程序
最新推荐文章于 2023-08-21 15:44:58 发布