Source of cppstr3.cpp


  1: // Filename: CPPSTR3.CPP
  2: // Purpose:  Illustrates input of lines, which may or may not be a
  3: //           full 80 characters, into C++ string objects with getline.

  5: #include <iostream>
  6: #include <string>
  7: using namespace std;

  9: #include "PAUSE.H"

 11: int main()
 12: {
 13:     cout << endl;
 14:     cout << "This program illustrates input of C++ string "
 15:          << "\"lines\" with getline.  Study the "            << endl
 16:          << "source code while running it.  Note that "
 17:          << "you get to choose the line length "             << endl
 18:          << "on each pass.  In response to each prompt "
 19:          << "for strings, enter either the two "             << endl
 20:          << "strings requested or an end-of-line to quit. "  << endl;
 21:     cout << endl;
 22:     Pause(0);

 24:     string s1, s2;

 26:     cout << "Enter the two lines below: "   << endl;
 27:     getline(cin, s1);
 28:     getline(cin, s2);

 30:     while (cin)
 31:     {
 32:         cout << "Here are the two lines:" << endl;
 33:         cout << s1 << "<<" << endl;
 34:         cout << s2 << "<<" << endl;
 35:         Pause(0);  cout << endl;

 37:         cout << "Enter the two lines below: "   << endl;
 38:         getline(cin, s1);
 39:         getline(cin, s2);
 40:     }

 42:     cout << endl;

 44:     return 0;
 45: }