How To Read a Line Using CPP
- 1). Right-click the C++ source code file you want to edit. Click "Open With;" then click the C++ compiler you want to use to edit the file.
- 2). Add the input and output library header. Copy and paste the following code to the beginning of your file:
#include <iostream> - 3). Type the "cin" function to retrieve an input line from the user:
String var;
cout << "Please enter your name";
cin >> var;
The code above prints out "Please enter your name" to the user and then waits for the user to enter a name. The name entered is stored in the "var" variable. - 4). Add a response for the input. After the user inputs the value, you send a response. The following code tells the user the value that was entered:
cout << "You entered: " << var;
Source...