C++ examples for File Stream:cin
Avoids buffer overflow with cin.width
#include <iostream> #include <iomanip> //for setw using namespace std; int main()// w ww . j a va 2 s .co m { const int MAX = 20; //max characters in string char str[MAX]; //string variable str cout << "\nEnter a string: "; cin >> setw(MAX) >> str; //put string in str, // no more than MAX chars cout << "You entered: " << str << endl; return 0; }