1: // Filename: CPPSTR4.CPP
2: // Purpose: Illustrates explicit delimiter with
3: // cin.getline and C++ string objects.
5: #include <iostream>
6: #include <string>
7: using namespace std;
9: int main()
10: {
11: string s1, s2;
13: cout << endl;
14: cout << "This program allows the user to choose"
15: << "the delimiter character which terminates" << endl
16: << "the reading of each of two strings, but "
17: << "not the maximum number of characters" << endl
18: << "read, since in the C++ string objects "
19: << "used to read there is essentially no " << endl
20: << "limit (at least no small limit) on the "
21: << "number of characters that can be read." << endl;
22: cout << endl;
24: char delimiter;
25: cout << "Enter the delimiter character: ";
26: cin.get(delimiter);
27: if (delimiter != '\n')
28: cin.ignore(80, '\n');
29: cout << endl;
31: cout << "Enter some text: " << endl;
32: getline(cin, s1, delimiter);
33: getline(cin, s2, delimiter);
35: cout << endl;
36: cout << "Here are the two strings "
37: << "as read (one per line):" << endl;
38: cout << s1 << "<<" << endl;
39: cout << s2 << "<<" << endl;
41: cout << endl;
43: return 0;
44: }