0

Okay so I am working on an external polyphase sort/merge and I am using peek to look at the next value in a file, there is just one problem. My peek gives me the wrong number, but if i just read the value it gives me the right value. What could be wrong?

Edited by kyle.mace.35

3
Contributors
3
Replies
17
Views
3 Years
Discussion Span
Last Post by mike_2000_17
0

peek() reads a single character from the text file -- it can't be used to read integers except that it read a single digit.

Edited by Ancient Dragon

0

You cannot peek for more than one character. However, you can use the tellg and seekg functions to restore the original position after having done a multi-character reading. As so:

int peek_int(std::istream& in) {
  std::streampos orig_pos = in.tellg();
  int result = 0;
  in >> result;
  in.seekg(orig_pos);
  return result;
};
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.