CPP Cafe

The Menu

 

Home -> Menu -> Putback

Putback, Peek, Get

output

 

#include <iostream>
using namespace std;

int main(){
char ch;

cout<<"Enter a string."<<endl;
cin.get(ch);

cout<<"ch ="<<" "<<ch<<endl;

cin.get(ch);

cout<<"ch ="<<" "<<ch<<endl;

ch = cin.peek();
cout<<"After Peek:"<<" "<<ch<<endl;
cin.get(ch);
cout<<endl;
cout<<"ch ="<<" "<<ch<<endl;
cin.putback(ch);
cin.get(ch);
cout<<"After putback:"<<" "<<ch<<endl;

}