Using istream::peek() to compare next value against current value

Programmer001

Why is my condition with peek() not returning FALSE when the next value is 50?

When my code has read in 40 from a file and compares if 50 is less than 40, it returns TRUE.This is obviously wrong and creating a bug in the order the numbers in my sub files appear.

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;
        }
    }

I put in a temp int to tell me what fin_dataFile.peek() was returning and I kept getting 32. This is the ascii value for a space. Makes sense because each number is space separated. I tried working around this by using:

if ((fin_dataFile >> std::ws).peek() < value)

But then peek() was still returning different numbers than in the text file.

Background:

I'm working on an external natural mergesort. My split function is not splitting the data correctly. It should read in a file of space separated numbers and split them into two sub files of sub sorted data. It does so, but not in the proper order.

My algorithm divides the numbers between files by comparing the next number in the main file using peek() with the current number that has been read in.

This is a sample text file of data to be split:

75 55 15 20 85 30 35 10 60 40 50 25 45 80 70 65
Sam Varshavchik

peek() peeks ahead at the next character in the file.

In your case, the next character in the file after "40" is a space character, ASCII space, or 32, which is less than 40.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Peek Value in Next Column

From Dev

Is it possible to peek at the next rand value

From Dev

Compare value against parameters in Drools

From Dev

How to compare a value against an array

From Dev

Traverse an array and compare the current key value pair with next one php

From Dev

Using a for loop to compare if current value is less than previous

From Dev

Compare the current value with previous value in a loop in java

From Dev

Add Current value to a list then compare with the last value

From Dev

compare 8bit value against 16bit value

From Dev

How to compare a value from UITextField against a CoreData value

From Dev

How to compare a value from UITextField against a CoreData value

From Dev

Return value of istream::get()

From Dev

Compare Value of Current Observation with First Observation

From Dev

How to compare dataGrid date value to current date?

From Dev

Access: Compare current field value in subquery

From Dev

How to compare List count against single integer value?

From Dev

Compare all objects in array by value against each other

From Dev

Is it possible to compare against zero value in a generic method extending Number?

From Dev

IIS rewrite to compare Cookie Value against database list

From Dev

How to compare List count against single integer value?

From Dev

Awk compare current with next

From Dev

R getting the next value of current column

From Dev

Checking a child value of database entry against the current user uid?

From Dev

Python - How to Compare a column value of one row with value in next row

From Dev

Using AsyncTasnk and return value and compare with other value

From Dev

Highcharts : compare current value/previous value to get the rate

From Dev

compare the current value with previous value of ajax success callback

From Dev

Check if next value is equal o current value in python loop?

From Dev

Stop current process of loop when null value and continue with next value

Related Related

  1. 1

    Peek Value in Next Column

  2. 2

    Is it possible to peek at the next rand value

  3. 3

    Compare value against parameters in Drools

  4. 4

    How to compare a value against an array

  5. 5

    Traverse an array and compare the current key value pair with next one php

  6. 6

    Using a for loop to compare if current value is less than previous

  7. 7

    Compare the current value with previous value in a loop in java

  8. 8

    Add Current value to a list then compare with the last value

  9. 9

    compare 8bit value against 16bit value

  10. 10

    How to compare a value from UITextField against a CoreData value

  11. 11

    How to compare a value from UITextField against a CoreData value

  12. 12

    Return value of istream::get()

  13. 13

    Compare Value of Current Observation with First Observation

  14. 14

    How to compare dataGrid date value to current date?

  15. 15

    Access: Compare current field value in subquery

  16. 16

    How to compare List count against single integer value?

  17. 17

    Compare all objects in array by value against each other

  18. 18

    Is it possible to compare against zero value in a generic method extending Number?

  19. 19

    IIS rewrite to compare Cookie Value against database list

  20. 20

    How to compare List count against single integer value?

  21. 21

    Awk compare current with next

  22. 22

    R getting the next value of current column

  23. 23

    Checking a child value of database entry against the current user uid?

  24. 24

    Python - How to Compare a column value of one row with value in next row

  25. 25

    Using AsyncTasnk and return value and compare with other value

  26. 26

    Highcharts : compare current value/previous value to get the rate

  27. 27

    compare the current value with previous value of ajax success callback

  28. 28

    Check if next value is equal o current value in python loop?

  29. 29

    Stop current process of loop when null value and continue with next value

HotTag

Archive