Write a program to show that the getline and three-argument get istream member func- tions both end the input string with a string-terminating null character. Also, show that get leaves the delimiter character on the input stream, whereas getline extracts the delimiter character and discards it. What happens to the unread characters in the stream?
What will be an ideal response?
Unread characters in the input stream are read by subseqent input statements.
```
#include
using namespace std;
const int SIZE = 80;
int main()
{
char array[ SIZE ]; // array to hold getline() input
char array2[ SIZE ]; // array to hold get() input
char c;// holds next input value
// prompt user to enter string and use getline() to store it
cout << "Enter a sentence to test getline() and get():\n";
cin.getline( array, SIZE, '*' );
cout << array << '\n';
cin >> c; // read next character in input
cout << "The next character in the input is: " << c << '\n';
// use get() to obtain next value held in array
cin.get( array2, SIZE, '*' );
cout << array2 << '\n';
cin >> c; // read next character in input
cout << "The next character in the input is: " << c << '\n';
} // end main
```
Enter a sentence to test getline() and get():
wishing*on*a*star
wishing
The next character in the input is: o
n
The next character in the input is: *
You might also like to view...
You can use the ____ to check which cells are referenced in the formula assigned to the active cell.
A. Formula Finder B. Range Finder C. Calculation Finder D. Function Finder
Twitter is considered a __________ platform because of the limited number of characters allowed in a message.
a. blogging b. microblogging c. bulletin board d. None of the above
In order for a VLAN to get its name, what is typically appended to the word "VLAN"?
A. A number B. A slash C. An IP address D. A MAC address
Which of the following is the correct syntax for displaying a toast message for a long length of time?
A. ?Toast.makeText(MainActivity.this, Toast.LENGTH_LONG.show("A toast message"); B. Toast.makeText(MainActivity.this, "A toast message", Toast.LENGTH_LONG).show( ); C. ?Toast.LENGTH_LONG(MainActivity.this, "A toast message", Toast.makeText).show( ); D. ?Toast.show(MainActivity.this, "A toast message", Toast.makeTest).LENGTH_LONG;