the function in_avail()

B

berkay

#include <iostream>
using namespace std;
int main () {
streamsize size;
char ch;
streambuf * pbuf;
pbuf = cin.rdbuf();
cout << "Please enter some characters: ";
cin >> ch;
size = pbuf->in_avail();

cout << "The first character you entered is: " << ch << endl;
cout << size << " additional characters in input buffer" << endl;
return 0;
}

i enter ball;the output is:
The first character you entered is:b
4 additional characters in input buffer.

i think it must print 3 add.chars
 
J

Jack Klein

#include <iostream>
using namespace std;
int main () {
streamsize size;
char ch;
streambuf * pbuf;
pbuf = cin.rdbuf();
cout << "Please enter some characters: ";
cin >> ch;
size = pbuf->in_avail();

cout << "The first character you entered is: " << ch << endl;
cout << size << " additional characters in input buffer" << endl;
return 0;
}

i enter ball;the output is:
The first character you entered is:b
4 additional characters in input buffer.

i think it must print 3 add.chars

Did you enter "ball" by pressing 'b', 'a', 'l', 'l' and the "Enter" or
"Return" key on your keyboard? Don't you think that the '\n'
generated by that final key counts as one character?
 

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

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top