473,395 Members | 1,527 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,395 software developers and data experts.

Non-Blocking Input in C++

This seems to be an impossible task, but here goes:

Im looking for a C++ stl non-blocking input routine.
I would normally be able to whip one up myself,
if the STL functions were behaving in MSVC++.

(This doesnt have to be portable necessarily, but at least mus work on
VC++)

I have:
-----------------------------------------------
// Fastforward
std::cin.seekg(std::ios_base::end);

// Execute all commands available in the buffer
while((int)std::cin.tellg() > 0)
{
// Rewind
std::cin.seekg(0);

// Extrapolate one line from the stream
std::cin.getline(buffer, 99, '\n');
command = buffer;
Execute(command);

// Fastforward
std::cin.seekg(std::ios_base::end);
}
-----------------------------------------------

But that seems to get stuck inside the while-loop after the first line
of text is passed (through a pipe).

It should also be noted that in every state of execution,
cin.rdbuf()->in_avail()
returns zero.

If someone could shed light on WHY
(int)std::cin.tellg()
returns 2 at the end of an empty input stream, that would be
appreciated as well.

Thank you in advance,
John Gietzen
"Spoonful of Tactic"

Oct 16 '05 #1
3 6590
On 16 Oct 2005 07:41:53 -0700, "Otac0n" <Sp**************@gmail.com>
wrote in comp.lang.c++:
This seems to be an impossible task, but here goes:

Im looking for a C++ stl non-blocking input routine.
I would normally be able to whip one up myself,
if the STL functions were behaving in MSVC++.


[snip]

There is no such thing as non-blocking input defined by the C++
language. You need a Windows specific solution,
news:comp.os.ms-windows.programmer.win32 is a good place to ask.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Oct 16 '05 #2
* Jack Klein:
On 16 Oct 2005 07:41:53 -0700, "Otac0n" <Sp**************@gmail.com>
wrote in comp.lang.c++:
This seems to be an impossible task, but here goes:

Im looking for a C++ stl non-blocking input routine.
I would normally be able to whip one up myself,
if the STL functions were behaving in MSVC++.


[snip]

There is no such thing as non-blocking input defined by the C++
language.


Uh, there is... Trouble is, it's not guaranteed to work (which is as one
would expect with standard streams: very little there is guaranteed to work).
I hate standard streams so I won't look it up for the OP, but perhaps someone
else will.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 17 '05 #3
Well, if I could merely COUNT exactly how many characters were in an in
stream without blocking, then i could devise my own solution, but as it
stands, none of the methods i have devised for that have worked.

Oct 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
22
by: Steve - DND | last post by:
We're currently doing some tests to determine the performance of static vs non-static functions, and we're coming up with some odd(in our opinion) results. We used a very simple setup. One class...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.