get与getline的区别

#include <iostream.h>

int main()
{
	const int SIZE=80;
	char buffer[SIZE];

	cout<<"Enter a sentence :\n";
	cin.read(buffer,20);
	cout<<"\n The sentence entered was :\n";
	cout.write(buffer,cin.gcount());
	cout<<endl;
	return 0;
	/* //get and getline 
	const int SIZE = 80;
	char buffer1[SIZE],buffer2[SIZE];

	cout<<"Enter a sentence :\n";
	//cin>>buffer1;
	cin.getline(buffer1,SIZE,'4');
	//cin.get(buffer1,SIZE,'4');
	cout<<"\n The string read with cin was :\n"
		<<buffer1<<endl;

	cin.get(buffer2,SIZE,'5');
	//cin.getline(buffer2,SIZE,'4');
	cout<<" Ther string read with cin.get was :\n"
		<<buffer2<<endl;
	return 0;

	/*   //Using member functions get ,put and eof.
	char c;
	cout<<"Before input, cin.eof() is "
		<< cin.eof()<<"\n Enter a sentence followed by end of file:\n";

	while((c = cin.get())!= EOF)     // get从指定的输入流中读取(输入)一个字符(包括空白字符),
									// 并返回该字符作为函数调用的值,当遇到输入流中的文件结束符时,返回eof.
		cout.put(c);          // put函数是将一个字符输出(可连续调用,因为其返回值为对象的引用). 
		//cout<<c;
	cout<<"\n EOF in this system is:" << int(c);
	cout<<"\n After input,cin.eof() is "<< cin.eof()<<endl;
	return 0;
	*/
}

你可能感兴趣的:(get与getline的区别)