【发布时间】:2014-08-31 19:40:33
【问题描述】:
正如我的标题所指出的, 我需要读取文本文件 (C++) 中的信息。 我看到许多涉及组织为数字或字符串列表的文本文件的示例,但在我的情况下,我需要提取文件(example.txt)中的信息,组织如下:
// This is the begin of the text file:
Here_the_coordinates_are_going_to_be_listed
Start
x y z
0 0 0
1 0 0
1 1 0
0 1 0
End
理想情况下,我会在“std::vector”中读取并存储“Start”和“End”之间包含的信息,这样矩阵就是一个 N x 3 向量:
matrix[i][j] = 0 0 0
1 0 0
1 1 0
0 1 0
我看了一下教程,到目前为止我得到的只是:
std::array<std::array<int , 5>, 7> matrix;
std::ifstream file("../test/matrix.txt");
for (unsigned int i = 0; i < 7; i++)
{
for (unsigned int j = 0; j < 5; j++) {
file >> matrix[i][j];
}
这使我可以读取仅写入数字的文件。
非常感谢,
dARIO
【问题讨论】:
-
你的代码就这些了吗?
-
不,如果文件很简单,我可以读取和存储矩阵,但在这种情况下,我不知道如何从文本文件的第 5 行填充矩阵。跨度>