c++ - Using cin.get() to grab a line of text, then using it in a loop to display that line? -
OK, so I've come to this code snippet in my textbook that will resonate every other character in user type is. Now, I understand every other character, but I'm having difficulty using cin.get (). I think why cin.get is first, but why is it inside the loop? I'm feeling that I'm not entirely about the nature of input streams ...
EDIT: It just clicked ... I'm stupid Thanks for clearing it.
CH Next; Int count = 0; Cout & lt; & Lt; "Enter a line of input: \ n"; Cin.get (next); While (next! = '\ N') {if ((count% 2) == 0) cout & lt; & Lt; the upcoming; Count ++; Cin.get (next); }
Thanks advance!
get
cin
in this case "grab a line of text" As you believe cin.get
in this case only holds one character with cin.get
you read the characters that the user is typing One by one, one by one. This is why you have cin.get
in a loop.
Comments
Post a Comment