C++ ifstream 读取行组

C++ ifstream Reading groups of lines

我正在尝试让我的 ifstream 读取多行文本并在到达特定字符后重新开始。

例如,myfile.txt 中有这个:

300 200 10 10 / 200 300 20 20

我想对每个人使用我的方法 LoadImg 4 行,这些行中的值是参数。我不确定会有多少块 4 行,但每行将用 /.

分隔

顺便说一句,我是 C++ 的新手。

你可以这样做

int i[4];
while (ifs >> i[0] >> i[1] >> i[2] >> i[3]) {
  // do some staff here with i[]

  ifs.get();  // get the trailing newline character '\n'
  if (ifs.peek() == '/')  // check the next character, because the last group has no '\'
    ifs.get();
}