You have the following code: string name; cout << "Enter your name : "; cin >> name; If a user enters "Mary Smith" at the prompt for a name, what will name contain after the cin statement

Respuesta :

ijeggs

Answer:

The variable name will contain Mary after the cin statement

Explanation:

The standard input statement cin in c++ does not read an entire line. When it is used, it read a value until it encounters a white space. The getline function should be used when you want to read a string that contains more than one word.

The code snipet below has been moderated to use a getline ()

#include <iostream>

using namespace std;

int main()

{

   string name;

   cout << "Enter your name : ";

  getline(cin, name);

   cout<<"The name is "<<name<<endl;

   return 0;

}

ACCESS MORE