C++

Objectives :

  • File Name: string_cin_copmare1.cpp
    Get continuous input from the user using either cin>> str1 or getline(cin,str1)
  • ios::cin is an object of class istream that represents the standard input stream. It corresponds to the cstdio stream stdin
  • Capturing a line with input:cin.
  • Code : string_cin_copmare1.txt 
 

Step: 1 Create a source file.

Step: 2 Edit and save Source file

Step: 3 Runtime Views:

Step: Brief Discussion

cin.get(char &ch) : Adds a character at the end of variable ch
Puts the next input character in the variable ch. Returns an integer value, which is zero if it encountered a problem (e.g. end of file).
cin.getline(char *buffer, int length)
Reads characters into the string buffer, stopping when (a) it has read length-1 characters or (b) when it finds an end-of-line character ('\n') or the end of the file. Stores a null character ('\0') after the last character read.
cin.read(char *buffer, int n)
Reads n bytes (or until the end of the file) from the stream into the buffer.
cin.gcount()
Returns the number of characters read by a preceding get, getline, or read command.
cin.ignore(int n)
Remove the next n characters (or until end of file) from the input stream, throwing them away into the Great Bit Bucket.
cin.putback(char ch)
Puts character ch back onto the stream. Bad things will happen if this character is not the one most recently extracted from the stream.