Variables

2.3 - Receiving multiple inputs


With std::cin the >> operator can be chained to receive more than one inputs.

This code creates the strings my_name and friend_name then inputs them.

std::string my_name{}, friend_name{};
std::cin >> my_name >> friend_name;

Task

Make the program receive my_name and friend_name as inputs.

  • Define my_name and friend_name with std::string my_name{}, friend_name{};.
  • Input my_name and friend_name with std::cin >> friend_name >> friend_name;.
#include <iostream> #include <string> int main() { // Create and input my_name and friend_name here! std::cout << "I'm " << my_name << " and this is my friend " << friend_name << std::endl; }