cin/cout

closed account (jLNv0pDG)
Is there any way (cout function?) to display the contents of the input queue without discarding them all?

Assuming I input "ABC", cin.get() takes "A" and leaves "BC" in the input queue, right?

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

int main ()
{
char letter;
cout << "Enter some letters: ";
letter = cin.get();
cout << "The first letter is " << letter;
cout << // [input queue]
return 0;
}
Last edited on
add the header <string>
then
1
2
string str;
getline(cin,str);

stores one line in str.
You can output it
 
cout << str << endl;

It will leave "B" "C" and "\n" in the queue. Other then that, yes.
datatype char stores only 1 character,thats why only A was displayed.change char to string.just follow anilpanicker.
Topic archived. No new replies allowed.