码迷,mamicode.com
首页 > 其他好文 > 详细

getline和get的区别

时间:2014-09-03 18:03:57      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   div   sp   log   

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

 

getline和get的区别

标签:style   blog   color   os   io   ar   div   sp   log   

原文地址:http://www.cnblogs.com/wuchanming/p/3954248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!