#include <string> #include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main(int argc, char* argv[])
{
ifstream ifile("1.txt");
string line, newline("");
int cnt=0; //计数器
getline(ifile,line); //读取文件一行
while (!ifile.fail())
{//循环读取文件
cnt++; //计数器累加
newline+=line; //字符串追加
if (cnt==6) //读取到6行时变更处理方式
{
newline+='/r/n'; //增加回车换行符号
cout<<newline<<endl<<endl; //测试程序是输出,可以改为写文件
newline=""; //初始化辅助数据
cnt=0;
}
else
{
newline+=','; //未满6行时,追加,字符
}
getline(ifile,line); //继续读取一行
}
return 0;
}
测试文本1.txt:
$WFE,1000.0440,W,09000.0000,Y,X,X,AA6
9980,0000043,0003440,040,040,040,002,023,030
8000,0054500,0005640,050,040,040,030,003,030
8596,0076700,0006340,300,450,023,230,300,030
5678,0004556,0045600,600,400,050,034,030,300
5665,4353000,0232434,340,034,045,320,030,200
$WFE,1000.0440,W,09000.0000,Y,X,X,AA6
9980,0000043,0003440,040,040,040,002,023,030
8000,0054500,0005640,050,040,040,030,003,030
8596,0076700,0006340,300,450,023,230,300,030
5678,0004556,0045600,600,400,050,034,030,300
5665,4353000,0232434,340,034,045,320,030,200
输出结果:
$WFE,1000.0440,W,09000.0000,Y,X,X,AA6,9980,0000043,0003440,040,040,040,002,023,0
30,8000,0054500,0005640,050,040,040,030,003,030,8596,0076700,0006340,300,450,023
,230,300,030,5678,0004556,0045600,600,400,050,034,030,300,5665,4353000,0232434,3
40,034,045,320,030,200
$WFE,1000.0440,W,09000.0000,Y,X,X,AA6,9980,0000043,0003440,040,040,040,002,023,0
30,8000,0054500,0005640,050,040,040,030,003,030,8596,0076700,0006340,300,450,023
,230,300,030,5678,0004556,0045600,600,400,050,034,030,300,5665,4353000,0232434,3
40,034,045,320,030,200
c++ txt文本文件提取
最新推荐文章于 2022-09-30 16:28:48 发布