C++找出特定字符串后读取后续内容

C++找到特定字符串后读取后续内容
初学C++,现在需要实现这么一个功能,如果在文件中找到了目标字符串(这个字符串占一行),那么就将后续的有内容的各行读入并保存在一个二维动态数组中,遇到第一个空行就结束。
需要保存在动态数组中的各行数据格式相同,是由若干个空格分开的六列正整数,在文件中查找字符串的功能已经写好了,那么要如何将后续的内容读入动态数组呢?二维数组很小,是用vector来保存好一些还是用二维指针新建动态数组好一些?谢谢先 C++找出特定字符串后读取后续内容

C++找出特定字符串后读取后续内容

------解决方案--------------------
还是直接上代码有说服力
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

struct Linedata    //定义结构存放每行数据
{
int data[6];
};

int main()
{
ifstream ifs("temp.txt");
string line;
while (ifs.good())
{
getline(ifs, line);
if (line == "CARFIN")
break;
}
if (!ifs.good())
{
cout << "没找到CARFIN,退出。\n";
exit(EXIT_FAILURE);
}
Linedata temp;
vector<Linedata> result;
while (true)
{
for(int i = 0; i < 6; i++)   //读一行中6个数据
ifs >> temp.data[i];
if (ifs.good())
result.push_back(temp);  //一行读完,push进容器
else
break;                   //文件流出错,就停止
}
ifs.close();
//显示读取的内容
for(vector<Linedata>::iterator it = result.begin(); it != result.end(); ++it)
{
temp = *(it);
for (int i = 0; i < 6; i++)
cout << temp.data[i] << ' ';
cout << endl;
}
return 0;
}


//test.txt
测试
CARFIN
0 1 2 3 4 5
6 7 8 9 0 1
2 3 4 5 6 7