版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_33232390/article/details/52576586
使用fstream库中函数读取文件内容并存入到另一个文件中的demo。
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <iostream>
#include <unistd.h>
#include <fstream>
#define MASK_FILE_PATH "./i2clog.csv"
#define OUTPUT_FILE_PATH "./i2cnew.csv"
using namespace std;
//读取mask
string cfgtemp;
fstream cfgfile;
ofstream i2clog;
int main()
{
cfgfile.open(MASK_FILE_PATH,ios::in);
if (!cfgfile.is_open())
{
cout << "Can not find mask file,system will work as No Mask Mode." << endl;
return 0;
}
i2clog.open(OUTPUT_FILE_PATH,ios::app);
//读取mask
int i;
while (!cfgfile.eof() )
{
cfgtemp = "";//清空缓存
/* for(i = 0; i < 1300 ; i++)
{
//使用这个/* */中是让其每1300行读取一次并赋值
cfgfile >> cfgtemp;
}*/
cfgfile >> cfgtemp;//文件中取一行数据
i2clog << cfgtemp << '\n';//写入一行数据到文件
}
i2clog.close();
cfgfile.close();
return 0;
}