I know what it does (gets the info from the user, and then gets rid of the newline), but was wondering how it works. Does the code read cin.get(name, size), then after something is inputed go back and basically re-read the line as cin.get()?
Also is cin.getline() better than cin.get() or is it one of those things that is preference?
Does the code read cin.get(name, size), then after something is inputed go back and basically re-read the line as cin.get()?
yes.
The istream.get functions all return a reference to the istream.
So cin.get(name, size) gets some characters and return a recference to cin
so you now have cin.get()
EDIT - for correctness:
I should have said that the istream.get functions all return an istream reference - except for
the get() function with no parameters whic return an integer.
The best way I can explain the first part, partly because it's something I'm just getting a hang of myself, is that this is possible because objects have methods that are objects that have methods ... or something like that ;). It is everlasting proof that Bjarne Stroustrup is a saddist.
cin.getline() and cin.get() are two different methods and accomplish two simular but different things. This is like asking if an apple is better then a pear, and saying they are both fruit and they both have vitamins.
cin.getline() works with strings and gets an entire line while cin.get() works with chars and gets only what you tell it to.