Answers for "C++ user input"

C++
13

user input c++

#include <iostream>
int main(){
  std::string firstname; //variable created as a string
  std::cout << "What's your first name\n";
  std::cin >> firstname;//asking for the users' first name
  std:: cout << "Hello " << firstname
}
//Works for anyone, don't need any packages, just type this is in and run it.
Posted by: Guest on June-04-2020
7

C++ user input

int x; 
cout << "hurry, give me a number!: "; // Type a number and press enter
cin >> x; // Get user input from the keyboard
cout << "you picked: " << x << " !" // Display the input value

OR use:
getline >> (cin, variable-name);
instead of 
cin >> x;
Posted by: Guest on May-01-2020

Browse Popular Code Answers by Language