- There are may problems that can arise with input, and we will deal with
most of them later. This is just to get started.
- Just like output is performed to the standard output stream cout
- input is performed from the standard input stream cin
- the operator >> is the stream extraction operator or get from
string aWord;
cin >> aWord;
- This will skip whitespace until non-whitespace is encountered.
- It will then read nonwhitespace characters into aWord until
another whitespace is encountered.
- Input to a character is even simpler
char aChar;
cin >> aChar;
- Will store the first non-whitespace character in aChar.
- It is always best to prompt (or ask) the user before performing input
- You should tell them you are going to do input
- You should tall them what you want.
- In fact, programs that don't prompt for imput are docked for points.
- It is also a good idea to echo back what was just entered.
- This lets the user know they typed in the right thing.
- For a while, it helps you understand what the io is doing.
- In Fact, if you don't echo back the results of input, you will be docked points.
string firstName;
cout << "Enter your First Name : " ;
cin >> firstName;
cout << endl;
cout << "You Entered your First Name as " << firstName << endl;