473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I use cin get() peek() and unget() without prompting the user for more input?

boxfish
469 Expert 256MB
Hello, I'm trying to make a kind of complicated overloaded input operator in C++, and I need to look ahead a couple of characters on the input stream, and not remove them from the stream until I know they're both the characters I want.

I use cin.peek() to see if the first character is what I want, and if it is, I use cin.get(). Then I use cin.peek() again for the second character to see if it's what I want, and if it is, I use cin.get() again. But if the second character isn't the one I want, I don't take it off the input stream, and I put the first one back on with cin.unget().

My problem is that if I use cin.unget() after I use cin.peek(), my program prompts the user for more input, even if there is lots more stuff waiting on the stream. I don't see why cin.unget() should prompt the user for input. It only does this after cin.peek().

My operating system is Windows XP, and I'm using the Dev-C++ development enviroment.

Thanks in advance for any help you can give me.
Mar 15 '08 #1
0 2022

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: el_roachmeister | last post by:
Is there a way to make a text link post to a form without passing all the parameters in the url? The urls tend to get very long and messy. I often wonder if there is a limit to how long they can...
9
by: Kevin Saff | last post by:
Why are these two similar functions provided? (unget & putback) I'm working with a file format where the type of record to read in next is stored in the first two bytes of the record. From a...
36
by: Wei Su | last post by:
Hi, I have a text file abc.txt and it looks like: 12 34 56 23 45 56 33 56 78 ... .. .. ... .. .. I want to get how many rows totally in the text file, how to do this? Thanks.
1
by: Shawn | last post by:
Hi. I'm using this code to loop through all the lines in a text field: While myStreamReader.Peek() > -1 myStreamReader.ReadLine() i = i + 1 End While Now, what I need to do is to loop through...
5
by: Avi Kak | last post by:
Hello: Does Python support a peek like method for its file objects? I'd like to be able to look at the next byte in a disk file before deciding whether I should read it with, say, the read()...
16
AnuSumesh
by: AnuSumesh | last post by:
Hi, I am ridirecting page to vbs file. File is running properly but it is asking user to open/save the file. But i want that it should run without any dialouge box. My code is : ...
6
by: python | last post by:
Is there an elegant way to unget a line when reading from a file/stream iterator/generator? By "unget" I mean a way to push back a line into the source stream and backtrack the...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net page, it uses js to print in IE. It always has the prompting user window appear. I have tried: <input onclick="document.all.WebBrowser.ExecWB(6,6)" type="button"...
2
by: Terry Reedy | last post by:
Luis Zarrabeitia wrote: Interesting observation. Iterators are intended for 'iterate through once and discard' usages. To zip a long sequence with several short sequences, either use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.