Friday, January 8, 2010

C++ coding question cin.get()?

i was wondering if i could put like cin.get(y) so it waits for y to be entered. is this possible.C++ coding question cin.get()?
If y is a char, it will only get one char.


If y is a char array, you would need to pass in the number of characters + 1 that you want to get.


If y is a char array, you could also pass in the character that acts as the end of line character.





Here are some web pages that describe how to use cin.get


http://www.cplusplus.com/reference/iostr鈥?/a>


http://www.minich.com/education/wyo/cplu鈥?/a>


http://www.cplusplus.com/forum/general/4鈥?/a>





Hope that helps.C++ coding question cin.get()?
No, that wouldn't be correct syntax.





A normal





cin %26gt;%26gt; y;





will wait for an input before the program continues.





cin.get(y) would mean that ';cin'; is an object of a class, and get() was a function of that class. I mean you could write up a class to do that but it would be rather pointless.
cin object





Standard input stream





cin is an object of class istream that represents the standard input stream. It corresponds to the cstdio stream stdin.





By default, most systems get their standard input from the keyboard, therefore cin is generally expected to get information from the user, although there are many cases where this can be redirected to some other source.





Because cin is an object of class istream, we can retrieve characters from cin either as formatted data using the extraction operator (%26gt;%26gt;) or as unformatted data using the read member function, among others (see istream).





cin is tied (see ios::tie) to the standard output stream cout, which means that cout's buffer is flushed (see ostream::flush) before each i/o operation performed on cin.

No comments:

Post a Comment