#include "../../std_lib_facilities.h"
struct Reading{
int hour;
double temperation;
Reading(int h, double t):hour(h),temperation(t) {};
};
void main()
{
cout<<"please enter input file name:"<<endl;
string name;
cin>>name;
ifstream ifst(name.c_str());
if(!ifst) error("can't open input file ",name);
cout<<"Please enter output file name:";
cin>>name;
ofstream ofst(name.c_str());
if(!ofst) error("can't open input file ",name);
vector<Reading> temps;
int hour;
double temperature;
while(ifst>>hour>>temperature )
{
if(hour <0 || hour > 23) error("hour out of range");
temps.push_back(Reading(hour, temperature));
}
for(int i = 0; i<temps.size(); ++i)
{
ofst<<'('<<temps[i].hour<<','<<temps[i].temperation<<")\n";
}
keep_window_open();
}
IO读取本地文件并创建一个新文件
最新推荐文章于 2020-07-21 19:48:35 发布
本文介绍了一个简单的C++程序,该程序从输入文件中读取小时和温度数据,并将这些数据存储为结构体数组。之后,程序将这些数据写入到另一个输出文件中。程序还包括错误检查,例如检查小时是否在有效范围内。
2011

被折叠的 条评论
为什么被折叠?



