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;
}

 

posted @ 2014-09-03 17:49  Jessica程序猿  阅读(525)  评论(0编辑  收藏  举报