Non-Blocking Input in C++

O

Otac0n

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"
 
J

Jack Klein

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,
is a good place to ask.
 
A

Alf P. Steinbach

* Jack Klein:
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.
 
O

Otac0n

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top