+ 1
i didnt get the concept of peek()
its a member function of istream classes...
2 odpowiedzi
+ 4
peek() allows you to check what is the first char that is coming from the input stream... without flushing in the stream yet...!!!
Try and run this code in CodePlayground... and see how it works:
// peek example
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string fullWord;
char firstChar = cin.peek();
cout << "The first char is " << firstChar << endl;
cin >> fullWord;
cout << "Your input was: " << fullWord;
return 0;
}
Notice that when this code is run it will not call for user input two times.... it will only call for input once, take a "peek" of the first char the user inputed and go on with the code...
+ 1
thanku