|
ex8-3.cpp - Example 8-3 istream member functions |
#include <iostream>
using namespace std;
int main()
{
char temp[80], ch;
cout << "Enter something => ";
// Get the first 6 bytes of the input buffer
cin.get(temp,7);
cout << "temp=" << temp << endl;
// Get the next 7 bytes of the input buffer
cin.get(temp,8);
cout << "temp=" << temp << endl;
// Get the next bytes from the input buffer
cin.get(ch);
cout << "ch=" << ch << endl;
// Get the rest of the input buffer until '\n' is read
while (cin.get(ch) && ch != '\n') {
cout << ch;
}
cout << endl;
cout << "Enter something else => ";
// Get some more data from the input buffer up to 'v'
cin.getline(temp,sizeof(temp),'v');
cout << "temp=" << temp << endl;
// Read 6 more bytes from the input buffer
cin.getline(temp,7);
cout << "temp=" << temp << endl;
// Read 1 more byte from the input buffer
cin.get(ch);
cout << "ch=" << ch << endl; // What happened here?
// Look at the next byte in the input buffer
cout << "cin.peek()=" << cin.peek() << endl;
// What is the state of cin
cout << "cin.rdstate()=" << cin.rdstate() << endl;
// Clear the state of cin
cin.clear();
// Read 1 byte from the input buffer
cin.get(ch);
cout << "ch=" << ch << endl;
// Write the last byte read back into the input buffer
cin.unget();
cin.putback('X');
cin.getline(temp,sizeof(temp));
cout << "temp=" << temp << endl;
cout << "Enter some more => ";
cin.read(temp,6);
cout << "cin.gcount()=" << cin.gcount() << endl;
cout << "temp=" << temp << endl;
cin.ignore(5);
cin >> temp;
cout << "temp=" << temp << endl;
cin.ignore(80,'\n');
cout << "Enter one last time => ";
// Read the first word from the input buffer
cin >> temp;
cout << "temp=" << temp << endl;
// Read 7 more bytes into temp
cout << "cin.readsome(temp,7)=" << cin.readsome(temp,7) << endl;
cout << "temp=" << temp << endl;
cout << "cin.readsome(temp,10)=" <<cin.readsome(temp,10) << endl;
cout << "temp=" << temp << endl;
return 0;
}
CIS27: Programming in C++ Instructor: Joe Bentley