Wednesday, February 17, 2010

What Is Cin What Is The Limitation Of Cin While Taking Input For Character Array?

What is the limitation of cin while taking input for character array? - what is cin

To understand this consider the following statements
char str [5];
cin>> str;
Enter the value of str, if you enter more than 5 characters then there is no provision in the NIC to test the limits of the table. If the table overflows, can be dangerous. This can be avoided by get () function. For example, consider the following statement,
cin.get (str, 5);

In the execution of this statement, if we enter more than 5 characters, then get () takes only the first five characters, and ignores the rest of the characters. Some other changes to get () are availableas follows:

(CH) get - Extracts a single character

get (str, n) - Extracts n characters to str

get (str, delim) - Extracts a character array str until the specified delimiter (eg "\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ n '). delimiter leaves in the flow.

get (str, n, delim) - Excerpts str character array to n characters or character DELIM leave delimiter into the stream.

No comments:

Post a Comment