i didnt get the concept of peek() | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

i didnt get the concept of peek()

its a member function of istream classes...

6th Aug 2016, 9:09 PM
Abhi Tiwari
Abhi Tiwari - avatar
2 ответов
+ 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...
6th Aug 2016, 10:56 PM
Nelson Urbina
Nelson Urbina - avatar
+ 1
thanku
7th Aug 2016, 5:49 PM
Abhi Tiwari
Abhi Tiwari - avatar