Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

2. assume a string object has been defined as follows: string descripti…

Question

  1. assume a string object has been defined as follows: string description; a) write a cin statement that reads in a one - word string. b) write a statement that reads in a string that can contain multiple words separated by blanks.

Explanation:

Step1: Read one - word string

In C++, to read a one - word string using cin, we can directly use cin with the variable name.
cin >> description;

Step2: Read multi - word string

To read a string that can contain multiple words separated by blanks, we use getline(cin, description);

Answer:

A. cin >> description;
B. getline(cin, description);