getline和get的区别

#include<iostream>

#include<fstream>

#include<cstring>

using namespace std;



int main()

{

    ifstream file("1.txt");

    char ch[20];

    cout<<"getline: "<<endl;

    while(file.getline(ch,1000000,'\n'))

        cout<<ch<<endl;

    //get调用之后只会显示一行,因为get不会丢弃流中的换行符

    cout<<"get:"<<endl;

    while(file.get(ch,1000000,'\n'))

        cout<<ch<<endl;

}

 

你可能感兴趣的:(get)