Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ Can someone explain these rules to me in more layman terms? Also, where woul

ID: 3853730 • Letter: C

Question

c++

Can someone explain these rules to me in more layman terms? Also, where would we place the cin.ignore (n, pattern) in the program above?

Thanks!

#include #include-: st ring» using namespace std; //There are a number of different tools we can access the standard input stream. The following are the two we'll use in this class: //1) The cin > var; command accesses input characters, ignores whitespace, and ignores the newline at the end of the user's input //we use this for gathering numerical input, and storing it in variable "var" //2) The getline(cin, s) command consumes all characters up to, and including, the new line character. //It then throws away the new-line, and stores the resulting string in s. We use this for gathering string inputs. [Requires the string library] /Although the 2 different input gathering tactics seem pretty straightforward,theres 1 issue with using cin >> var; and then after using getline cin, s) //Since cin var leaves a newline, and getline(cin, s) consumes all characters up to and including a new line, //using the first before the second will cause the leftover newline character to be interpretted as hitting enter without any text on the second /To illustrate this problem, see the following example: int main () { string inputString; int inputInt; cout

Explanation / Answer

The basic difference between cin and getline is that in cin it does not read any extra space it uses as termination point but in case of getline it doenot count whutespace as termination it includes all. Another one is cin will take input for any particular input stream but getline will take input for any input stream.

cin. ignore should be placed after the cin statement (cin<<<InputInt)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote