getline和get的区别

时间:2021-10-06 09:01:51
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std; int main()
{
ifstream file("1.txt");
char ch[];
cout<<"getline: "<<endl;
while(file.getline(ch,,'\n'))
cout<<ch<<endl;
//get调用之后只会显示一行,因为get不会丢弃流中的换行符
cout<<"get:"<<endl;
while(file.get(ch,,'\n'))
cout<<ch<<endl;
}