126k views
20 votes
Which statement will read an entire line of input into the following string object?

Select one:
a. cin << address;
b. cin address;
c. getline(cin, address);
d. cin.get(address);
e. None of these

User GoldenAge
by
5.6k points

1 Answer

1 vote

Answer:

getline(cin, address);

Step-by-step explanation:

Given

String object: address

Required

Statement that reads the entire line

The list of given options shows that the programming language is c++.

Analysing each option (a) to (e):

a. cin<<address;

The above instruction will read the string object until the first blank space.

Take for instance:

The user supplied "Lagos state" as input, only "Lagos" will be saved in address using this option.

b. cin address:

This is an incorrect syntax

c. getline(cin,address);

Using the same instance as (a) above, this reads the complete line and "Lagos state" will be saved in variable address

d. cin.get(address);

address is created as a string object and the above instruction will only work for character pointers (i.e. char*)

From the above analysis, option (c) is correct.

User Jens Mikkelsen
by
4.9k points