Multiple choice

Observe the following statements and decide what do they do: string mystring; getline(cin, mystring);

  1. reads a line of string from cin into mystring

  2. reads a line of string from mystring into cin

  3. cin cannot be used in this way

  4. Function declaration is wrong

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The getline(cin, mystring) function reads a complete line of text from the input stream (cin) and stores it in the string variable mystring. Unlike cin >> mystring which stops at whitespace, getline reads until a newline character. Option B is reversed (cin is the source, not destination). Option C is incorrect because getline is a standard valid function.