/* Includes the syntax for inputting C strings from the keyboard. Note how to use setw and cin.ignore. */ #include #include #include void main(){ const int WORD_LENGTH = 15, MULTILINES = 800, LINE = 100; char aa[WORD_LENGTH], bb[MULTILINES], cc[3][LINE]; ifstream infile ("inp_string.dat"); int i; cout << "Enter a single word: "; cin >> setw(sizeof(aa)) >> aa; /* To avoid writing beyond end of array aa.*/ cin.ignore (1000,'\n'); /* Ignore the next 1000 characters up to the next \n character*/ cout << aa << endl << endl; cout << "Enter a line. " << endl; cin.getline (bb,sizeof(bb)); // cin.ignore (1000, '\n'); cout << bb << endl << endl; for (i=0; i<3; i++){ infile.getline(cc[i], sizeof(cc[i])); cout << cc[i] << endl; } }