Sorry if I was unclear Andy, I meant that when I said "get() needs a delimiter, but I just want to extract a single character without waiting for anything."
Thanks anyways. I presume writing my own function for something like this would be very complex, but if it's not that complex then I'm up for it, where do I start?
One question: 'How' does get() wait for an enter? Does it read stdin until it sees a '\n'?
My second question would be: Is there any reason istream::putback() should not be used to insert characters to stdin?
If get() reads for '\n' and putback() can be used, then we might use them with peek() to insert '\n' to the stdin. Is that too crazy?
Is there a better way? Like essentially modifying get() to not wait for '\n' ourselves? Would that be too complex?
Edit:
1 2 3
|
cin.putback('x');
char c;
c= cin.get();
|
That code executes without waiting for the enter button to be pressed.. Anybody knows why??
Oh and also this doesn't work:
1 2 3 4 5 6 7
|
cin.putback('x');
cin.putback('t');
char c;
c= cin.get();
cout << (int)c;
c = cin.get();
cout << (int)c;
|
Both cout statements give blanks.
If putback() is the wrong way of inserting to stdin, how do you insert to stdin?