我处理一些数据,其中列中的数据如下:
1 -0.004002415458937208 0.0035676328502415523
2 -0.004002415796209478 0.0035676331876702957
....
我只对最后两个值感兴趣。通常,我会将这些值读为:
std::ifstream file(file_name);
double a, b;
for (lines) {
// | throwing away the first value by reading it to `a`
file >> a >> a >> b;
store(a, b);
}
我不确定这对其他人来说是否易读,当数据结构未知时可能被视为错误。 我是否可以做些什么使其更加明确,以便真正丢弃第一个读取的值? 我希望得到以下内容,但没有任何效果:
file >> double() >> a >> b; // I hoped I could create some r-value kind of thing and discard the data in there
file >> NULL >> a >> b;
_
是一个有效的标识符,我曾见过它被用作变量的占位符。其他类似的名称包括:discarded
、ignored
、consumed
、unused
和destroyer_of_hope
(好吧,最后一个不算)。 - jaggedSpirefile >> junk >>...
可以起到作用。这是我丢弃输入的做法。 - Topological Sort