title: How does cin.peek() work in c++?
body: <p>when i use cin.peek() with a "char" data type it works perfectly fine but it does not work with "string" data type.
  this works fine:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int main(){
    cout&lt;&lt;"enter a word"&lt;&lt;endl;
    char a;
    cin&gt;&gt;a;
  if(cin.peek()=='c'){
    cout&lt;&lt;"ha"&lt;&lt;endl;
  }
  return 0;
  }
  </code></pre>
  
  <p>if input is "dce" it prints "ha" but
   the code below doesnot do the same job:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  int main(){
    cout&lt;&lt;"enter a word"&lt;&lt;endl;
    string a;
    cin&gt;&gt;a;
  if(cin.peek()=='c'){
    cout&lt;&lt;"ha"&lt;&lt;endl;
  }
  return 0;
  }
  </code></pre>
  
  <p>isn't the string data type more appropriate as we are storing words in "a" variable. can "char" data type be used to store words or only single letters?</p>