peek函数的用法

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     char c[20];
 7     int ch;
 8     cout<<"please enter a sentence:"<<endl;
 9     cin.getline(c,15,'/');
10     cout<<"The first part is:"<<c<<endl;
11     ch=cin.peek();
12     cout<<"The next character(ASCII code) is:"<<ch<<endl;
13     cin.putback(c[0]);
14     cin.getline(c,15,'/');
15     cout<<"The second part is:"<<c<<endl;
16     return 0;
17 }

 

posted @ 2018-08-02 10:20  borter  阅读(477)  评论(0编辑  收藏  举报