C++cin学习

cin.get() 和 cin.get(char)

  1. If you want a program to examine every character, you should use one of the get() methods. For example, a word-counting program could use white space to determine when a word came to an end. Of the two get() methods, the get (char &) has the classier interface. The main advantage
    of the get() method is that it closely resembles the standard C getchar() function, which means you can covert a C program to a C++ program by including iostream instead of stdio.h, globally replacing getchar() with cin.get(), and globally replacing C’s putchar(ch) with cout.put(ch).
  2. If skipping white space is convenient, you should use the extraction operator, >>.

String Input: getline(), get (), and ignore()

istream & get(char *, int ,char);
istream &get(char *, int)
istream & getline(char* , int,char);
istream & getline(char*,int );
char line[50];
cin.get(line,50);

The cin.get() function quits reading input into the array after encountering 49 characters or, by default, after encountering a newline character, whichever comes first.

The chief difference between get() and get getline() is that get() leaves the newline character in the input stream, making it the first character seen by the next input operation, whereas getline() extracts and discards the newline character from the input stream.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值