User input – C++

What it does:

It prompts the user to enter there name. It will then read in the data which the user has entered and print it out to them.

I have now included namespace std as it automatically includes the std rather than me having to type out std::cout loads of times.

Code:


#include <iostream>
using namespace std;

int main()
{
    string userInput;

    cout << "Please enter your name";

    cin >> userInput;

    cout << "Your name is " + userInput;

    return 0;
}//main

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s