What is diffrence between cin.get(ch) and ch=cin.get()?He re ch is a char variable.
What is the difference between cin.get(ch) and ch=cin.get()?
Collapse
X
-
Tags: None
-
Difference is that cin.get(ch) returns an istream object, while cin.get() returns the read character as an integer.
First version allows you to more easily read the stream in a loop because it returns an istream object which got boolean conversion so you can do the following(e.g):
Code:char c; while(cin.get(c)) { //do something }
Code:char c; while(cin.fail()==false) { c = cin.get(); //do something }
Comment