Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: C++  |  size: 0.44 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     char buf[256];
  9.  
  10.     // Read in a single word
  11.     cin >> buf;
  12.  
  13.     cout << "Received: " << buf << endl;
  14.  
  15.     // Clear error bits
  16.     cin.clear();
  17.     // Clear stdin
  18.     cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
  19.  
  20.     // Get a string up to a newline
  21.     cin.getline(buf, 256);
  22.  
  23.     cout << "Received: " << buf << endl;
  24.  
  25.     return 0;
  26. }