繁体   English   中英

文件读取在某些行后停止

[英]File reading sort of stops after some lines

我必须阅读总是有N行的文件input.txt。 每行由两个整数组成。 具体来说,我正在读取两个整数均为2 ^(line_index -1)的文件。

int temp1, temp2;
std::vector<int> vec1, vec2;
std::fstream fh("input.txt", std::ios_base::in);    
for (int i = 0; i < N; i++) {
    fh >> temp1 >> temp2;
    vec1.push_back(temp1);
    vec2.push_back(temp2);
}
//first few lines of input are
//1 1
//2 2
//4 4
// . . . 
//Line 31 should be: 2147483647 2147483647
//but my code read it as 2147483647 1073741824
//This is always the case for N>30

在第30行之后,如您在上面的代码段中所见,文件读取变得很奇怪。 我的代码有问题吗? 还是我读取文件类型的方法限制了我可以输入的变量?

您即将达到整数限制,例如参见此问题 不确定为什么要执行此操作,但是如果要保存更大的值,则需要其他数据类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM