Refers to a non-destructive operation performed on sequential, collection-like data structures that have the notion of "top element" or "next element", such as stacks, queues and streams. The `peek` operation returns the value of the "top" (or "next") element without "consuming" that element, i.e. without removing that element from the data structure.
Questions tagged [peek]
163 questions
2
votes
0 answers
Writing parser in Rust - peeking two chars ahead
I'm working on a parser in Rust. The goal is to parse into an AST and then use serde to serialize the AST into JSON.
The DSL that I'm going to parse is semi-similar to JavaScript, but much simpler.
pub struct Parser<'a> {
source:…

zbraniecki
- 49
- 3
2
votes
2 answers
peek multiple chars from cin with putback
I need to try to peek multiple characters from a std::istream (which could be std::cin), so I wrote a simple loop to call get() lots of times and then putback() lots of times:
std::vector peek_many(std::istream& is, int N) {
…

Barry
- 286,269
- 29
- 621
- 977
2
votes
1 answer
Overloading the istream >> operator for a rational number class. Don't know how to deal with integers
I am learning C++ and am doing a project dealing with a class that represents rational numbers (such as ½). I have overloaded the istream >> operator so that it correctly reads rational numbers from the stream.
I am having an issue with taking in an…

Luciano
- 27
- 3
2
votes
1 answer
Using istream::peek() to compare next value against current value
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…

Programmer001
- 2,240
- 2
- 19
- 35
2
votes
4 answers
Checking if the next element in a python list is empty
So what I am trying to accomplish is to check whether an element is empty by using a counter + 1 but I keep getting index out of range which essentially means the next element doesnt exist, but instead of throwing an exception I want the program to…

BasicHorizon
- 191
- 2
- 14
2
votes
5 answers
How do I subscribe to a MSMQ queue but only "peek" the message in .Net?
We have a MSMQ Queue setup that receives messages and is processed by an application. We'd like to have another process subscribe to the Queue and just read the message and log it's contents.
I have this in place already, the problem is it's…

Paul Lemke
- 5,494
- 3
- 47
- 66
2
votes
2 answers
Is there any way to "peek" at a file while it's uploading through HTTP onto a Windows box?
I need to add a file upload function to an ASP.NET website and would like to be able to read a small portion of the file on the server while it's still uploading. A peek or preview type function so I can determine contents and give some feedback to…

iisystems
- 1,089
- 1
- 11
- 12
2
votes
2 answers
how to peek at a single char in a non-buffered reader in java
I'm writing a program that takes a Reader and parses input from that reader. I cannot use a BufferedReader, but I would like to implement a peek method that looks at the current char in the reader, without actually calling read() on that character.…

user1601687
- 33
- 3
2
votes
2 answers
Similar function peek( ); (from C++) in Ruby
Is there any similar peek(); (From C++) function in ruby? Any alternative to do this?
I've found a way to do this.
Use the StringScanner:
require 'strscan'
scanner = StringScanner.new(YourStringHere)
puts scanner.peek(1)
You can use the…

André Castro
- 83
- 10
1
vote
1 answer
swap bufio.Reader.Peek with my own implementation
We have a case where we need to peek certain amount of incoming characters. The length for which is not fixed. bufio.Reader.Peek can only peek up to the maximum size of its initialized buffer. Any attempt to Peek larger results in…

D3XT3R
- 181
- 2
- 15
1
vote
2 answers
Devel::Peek Question
% perl -Ilib -MDevel::Peek -le '$a="34567"; $a=~s/...//; Dump($a)'
SV = PV(0x8171048) at 0x8186f48 # replaced "12345" with "34567"
REFCNT = 1
FLAGS = (POK,OOK,pPOK)
OFFSET = 3
PV = 0x8181bdb ( "34\003" . ) "67"\0
CUR = 2
LEN =…

sid_com
- 24,137
- 26
- 96
- 187
1
vote
1 answer
How to use correctly the return value from std::cin.get() and std::cin.peek()?
I've been always using peek(), get() this way:
int main(){
std::string str;
int value{};
if(std::isdigit(std::cin.peek()))
std::cin >> value;
else
std::getline(cin, str);
std::cout << "value : " << value << '\n';
…

Maestro
- 2,512
- 9
- 24
1
vote
1 answer
ifstream from named pipe - check nonblocking if there is data
To check 'regular' std::istream if there is any pending data I can do just something like this:
bool has_pending_data(std::istream& s) {
return s.peek() >= 0;
}
However, this is different for standard input and named pipes. If I do something like…

bartop
- 9,971
- 1
- 23
- 54
1
vote
2 answers
Replicate Java peek stream method in Clojure
In Java I can do this
list.stream().peek(System.out::println).filter(i -> i >= 0).findFirst();
This will find the first positive number in a list, printing all numbers since the begining until the first positive number.
I need something similar in…

Ionut Bilica
- 424
- 1
- 5
- 11
1
vote
0 answers
XML Documentation Navigation for C++ in Visual Studio (as in C#)
There is XML Documentation support for Visual C++ with IntelliSense and all for some time now.
Navigation from XML documentation, peek help etc. does not work though. Coming from C#, I dearly miss those functionalities.
Is there a way to enable this…

ktnr
- 245
- 2
- 9