我希望从文件中读取如下格式的输入:
sphere 3 2 3 4
pyramid 2 3 4 12 3 5 6 7 3 2 4 1 2 3
rectangle 2 3 4 1 9 12
我想要做类似以下操作:
char name[64];
int arr[12];
ifstream file (..);
while(file)
{
file >> name;
while( //reach end of line)
file >> arr[i]
}
您可以看到,我不知道会输入多少个整数,这就是为什么我想在新行停止。我使用getline实现了这一点,然后拆分了行,但他们告诉我只能使用 >> 运算符来完成。
注意:我不能使用 std::string
或 std::vector
。