C++ 使用istream::peek()将下一个值与当前值进行比较

C++ 使用istream::peek()将下一个值与当前值进行比较,c++,comparison,mergesort,istream,peek,C++,Comparison,Mergesort,Istream,Peek,为什么我的peek()条件在下一个值为50时不返回FALSE? 当我的代码从一个文件中读入40并比较50是否小于40时,它返回TRUE。这显然是错误的,并且按照子文件中的数字出现的顺序创建了一个bug while (fin_dataFile >> value) //fin_dataFile is type ifstream reading the original data { // write the int stored in value to the s

为什么我的peek()条件在下一个值为50时不返回FALSE?

当我的代码从一个文件中读入40并比较50是否小于40时,它返回TRUE。这显然是错误的,并且按照子文件中的数字出现的顺序创建了一个bug

while (fin_dataFile >> value) //fin_dataFile is type ifstream reading the original data
    {
        // write the int stored in value to the second sub file
        // fout_splitFile2 is type ofstream
        fout_splitFile2 << value << " ";

        // if the next value in the original data set is less than the current value
        // that was read, break the loop so we can read in that next value to store it
        // in the first sub file instead 
        if (fin_dataFile.peek() < value)
        {
            break;
        }
    }
peek()
向前查看文件中的下一个字符


在您的情况下,“40”之后的文件中的下一个字符是空格字符、ASCII空格或32,小于40。

您确定要将数字文本转换为可以进行计算的实整数吗?因为值是int类型,编译器不是将数字读取为int而不是chars吗?通过调试程序,每次我读入一个值时,值本身似乎都保持正确的值。
peek()
返回存储为整数的下一个字符。对于窄字符流,只有一个字节的数据。我认为这是你的误解。自从我使用C++流以来,已经有一段时间了,但是我认为它是文本不整数的。我想象peek()的工作原理与提取操作符类似。我已经有一段时间没用了。所以我需要一种方法,向前看两个字符,跳过空白。。。谷歌搜索一个可能性,我正在阅读关于seekg()的文章,看看这是否可行。。。
if ((fin_dataFile >> std::ws).peek() < value)
75 55 15 20 85 30 35 10 60 40 50 25 45 80 70 65