27-1Streams - #include <iostream> #include...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <iomanip> #include <cmath> using namespace std; void CinLooping() { int grade, highestGrade = -1; cout << "Enter grade (enter end-of-file to end): "; while ( cin >> grade ) { if ( grade > highestGrade ) highestGrade = grade; cout << "Enter grade (enter end-of-file to end): "; // CTRL-Z usually } // end while cout << "\n\nHighest grade is: " << highestGrade << endl; } int GetPut() { char c; cout << "Before input, cin.eof() is " << cin.eof() << "\nEnter a sentence followed by end-of-file:\n"; while ( ( c = cin.get() ) != EOF ) cout.put( c ); cout << "\nEOF in this system is: " << c; cout << "\nAfter input, cin.eof() is " << cin.eof() << endl; return 0; } int CinGet() { const int SIZE = 80; char buffer1[ SIZE ], buffer2[ SIZE ]; cout << "Enter a sentence:\n"; cin >> buffer1; cout << "\nThe string read with cin was:\n" << buffer1 << "\n\n"; cin.ignore(); cin.get( buffer2, SIZE ); cout << "The string read with cin.get was:\n" << buffer2 << endl; return 0; } int CinGetline() { const int SIZE = 80; char buffer[ 4 ]; /*if (cin.peek() == '\n') cin.ignore();*/ cout << "Enter a sentence:\n"; cin.getline( buffer, SIZE );
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cout << "\nThe sentence entered is:\n" << buffer << endl; return 0; } int CinRead() { const int SIZE = 80; char buffer[ SIZE ]; cout << "Enter a sentence:\n"; cin.read( buffer, 20 ); cout << "\nThe sentence entered was:\n"; cout.write( buffer, cin.gcount() ); cout << endl; return 0;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

27-1Streams - #include &lt;iostream&gt; #include...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online