马赛克007欢迎你

htt://shexinwei.blogbus.com

http://www.cppblog.com/shexinwei

感谢大家的支持

the difference of some Input function

1 /* 2 Subject: the difference of gets(),getch(),getchar() and getline() 3 Author: shexinwei 4 School: xidian university 5 Date: 2010-09-09 6 Laguage: C++ 7 IDE: visual studio 6.o 8 Version: 1.0 9 Modify Time: 2010-09-09 10 */ 11 #include <iostream> 12 using namespace std; 13 #include <conio.h> 14 #define MAX_LEN 20 15 int main() 16 { 17 18 //gets() : Get a line from the stdin stream. 19 //Get a line from the stdin stream. 20 21 cout<<"the function gets():"<<endl; 22 char buffer[MAX_LEN]; 23 gets(buffer); 24 cout<<buffer<<endl; 25 26 // getchar(): 27 // marco: #define getchar() getc(stdin) File: STDIO.H Get a character from a file; 28 // function: _CRTIMP int __cdecl getchar(void); File: STDIO.H Get a character from stdin; 29 char tmp = 0; 30 cout<<endl<<endl<<"the function getchar():"<<endl; 31 cout<< (char)getchar(tmp) <<endl; 32 33 //getline(): 34 //basic_istream<Elem, Tr>& getline(char_type *_Str, streamsize _Count); 35 //Gets a line from the input stream. 36 cout<<endl<<endl<<"the function getline():"<<endl; 37 cin.getline(buffer,MAX_LEN); 38 cout<<buffer<<endl; 39 40 //getch(): 41 //This POSIX function is deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant _getch instead 42 //Gets a character from the console without echo. 43 //int _getch( void ); 44 //Returns the character read. There is no error return. 45 //Headers: <conio.h> 46 cout<<endl<<endl<<"the function getch():"<<endl; 47 tmp = getch(); //without echo 48 // cout<<tmp<<endl; //print the character 49 50 51 system("pause"); 52 return 0; 53 54 }

posted on 2010-09-10 08:44 马赛克007 阅读(1387) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

公告

QQ:306334649 本博客所发代码皆为作者原创,大家可以随便使用。

常用链接

留言簿(1)

随笔档案

文章分类

我的博客

搜索

最新评论

阅读排行榜

评论排行榜