档案阅读有些线路后停止

File reading sort of stops after some lines

本文关键字:线路 档案      更新时间:2023-10-16

我必须读取一个始终具有n行的文件输入。每行由两个整数组成。具体来说,我正在读一个文件,其中两个整数均为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行之后,正如您在上面的摘要上看到的那样,文件读数变得很奇怪。我的代码中有问题吗?或我读取文件限制的方法我可以输入的变量?

您正在达到整数限制,例如,请参见此问题。不知道为什么要这样做,但是如果要节省更大的值,则需要其他数据类型。