/*
Subject: the difference of gets(),getch(),getchar() and getline()
Author: shexinwei
School: xidian university
Date: 2010-09-09
Laguage: C++
IDE: visual studio 6.o
Version: 1.0
Modify Time: 2010-09-09
*/
#include <iostream>
using namespace std;
#include <conio.h>
#define MAX_LEN 20
int main()
{
//gets() : Get a line from the stdin stream.
//Get a line from the stdin stream.
cout<<"the function gets():"<<endl;
char buffer[MAX_LEN];
gets(buffer);
cout<<buffer<<endl;
// getchar():
// marco: #define getchar() getc(stdin) File: STDIO.H Get a character from a file;
// function: _CRTIMP int __cdecl getchar(void); File: STDIO.H Get a character from stdin;
char tmp = 0;
cout<<endl<<endl<<"the function getchar():"<<endl;
cout<< (char)getchar(tmp) <<endl;
//getline():
//basic_istream<Elem, Tr>& getline(char_type *_Str, streamsize _Count);
//Gets a line from the input stream.
cout<<endl<<endl<<"the function getline():"<<endl;
cin.getline(buffer,MAX_LEN);
cout<<buffer<<endl;
//getch():
//This POSIX function is deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant _getch instead
//Gets a character from the console without echo.
//int _getch( void );
//Returns the character read. There is no error return.
//Headers: <conio.h>
cout<<endl<<endl<<"the function getch():"<<endl;
tmp = getch(); //without echo
// cout<<tmp<<endl; //print the character
system("pause");
return 0;
}