一、代码
get()、peek()
get(char&)、get(char*, int, char='\n')
read(char*, int)
put(char)
write(char*, int)
#include <iostream>
#include <cstring>
using namespace std;
//get()、peek()
//get(char&)、get(char*, int, char='\n')
//read(char*, int)
//put(char)
//write(char*, int)
int main(int argc, char*argv[])
{
//cin.get()
cout<<"cin.get(): "<<cin.get()<<endl;
//cin.peek()
cout<<"cin.peek(): "<<cin.peek()<<endl;
//cin.get(char&)
char c;
cin.get(c);
cout<<"cin.get(char&): "<<c<<endl;
//cin.get(char*, int, char='\n')
char buf[10];
cin.get(buf, 5);
cout<<"cin.get(char*, int, char): "<<buf<<endl;
//cin.read()
bzero(buf, 10);
cin.read(buf, 8);
cout<<"cin.read(): "<<buf<<endl;
//cout.put() cout.write();
cout<<"cout.put().write(): ";
cout.put('a').put('b').write("cdefg", strlen("cdefg")).put('\n');
return 0;
}
二、输出结果