There are several uses of the getline function. Assume the definition, string line1, line2; Which one of these allows specification of the character on which input stop?
a. cout << “Enter a line of input \n”;
getline(cin, line1);
b. cout << “Enter a line of input \n”;
getline(cin, line1, ‘?’);
c. cout << “Enter a line of input \n”;
getline(cin, line1) >> line2;
b) reads a line of input up to the first question mark. To select another stop-input character, replace the question mark.
Explanation: a) reads input up to the first newline, c) reads input into line1 up to the first newline, then puts all nonwhitespace from a second line of input into line2 . The reason this works is that getline returns a reference to cin which may be used with the extraction operator >> to extract another line into another variable.
You might also like to view...
Match the following file types with their file size comparison:
I. Document II. Picture file (JPG) III. Music file (MP3) IV. DVD disc V. Blu-Ray disc A. 1 MB B. 5 MB C. 25 GB D. 25 KB E. 4.7 GB
You cannot begin the name of a bookmark with a(n) ________
Fill in the blank(s) with correct word