C ++从文件读取 [英] C++ read from file
本文介绍了C ++从文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我知道在第一个值之后有多少个int值,但是我不知道它们之后有多少个值,那么应该如何读取这个文件。我的问题是,当我必须阅读包含2个值的行。
编辑:这是我的文件
5
27
15
42
17
35
20 1
28 2
43 3
这是我试过的:
fin>> N;
for(i = 1; i <= n; i ++)
fin>>部分[I]; $!
$ b while(!fin.eof())
{
nrT ++;
fin>> TRIC [NRT] [0];
fin>> TRIC [NRT] [1];
$ / code>
解决方案
{
tric [nrT] [0] = a;
tric [nrT] [1] = b;
}
How should I read this file if I know how many int values are after the first value but I don't know how many values are after them. My problem is when I have to read the lines that contains 2 values.
Edit: This is my file
5
27
15
42
17
35
20 1
28 2
43 3
Here is what I tried:
fin >> n;
for (i=1; i<=n; i++)
fin >> part[i];
while(!fin.eof())
{
nrT++;
fin >> tric[nrT][0];
fin >> tric[nrT][1];
}
解决方案
for (int a,b; fin >> a >> b; nrT++)
{
tric[nrT][0] = a;
tric[nrT][1] = b;
}
这篇关于C ++从文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文