读取时会自动将空格忽略,只读取数字。
#include <fstream>
using namespace std;
int main(int argc, char ** argv)
{
int num;
long double time;
char kg;
int a=1, b=2;
struct timeval t_start, t_end;
long double t;
ifstream fin("/home/flk/fea_num6.txt",ios::app);//
while (1)
{
sleep(1);
cout.setf(ios::fixed,ios::floatfield);//十进制计数法,不是科学计数法
cout.precision(2);//保留2位小数
ofstream fout_num("/home/flk/fn_ext.txt",ios::app);
// ofstream fout_kg("/home/flk/kg_ext.txt",ios::app);
ofstream fout_time("/home/flk/time_ext.txt",ios::app);
if(fin.is_open()&&fout_num.is_open()&&fout_time.is_open())
{
cout<<"open scueess"<<endl;
} else{
cout<<"open faile"<<endl;
}
fin>>num;
cout<<"num: "<<num<<endl;
fout_num<<num<<" ";
fin>>time;
cout<<"time: "<<time<<endl;
fout_time<<time<<" ";
if(fin.eof())
{
cout<<"finish"<<endl;
fin.close();
fout_time.close();
// fout_kg.close();
fout_num.close();
return 1;
}
}
return 0;
}