Ask Question

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

+1
Answers (1)
  1. 3 February, 07:59
    0
    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

    using namespace std;

    int main ()

    {

    string name;

    cout << "Enter your name : ";

    getline (cin, name);

    cout<<"The name is "<
    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “You have the following code: string name; cout name; If a user enters "Mary Smith" at the prompt for a name, what will name contain after ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers