首页 > 编程语言 > 详细

C++ 文件读取

时间:2016-03-16 22:38:08      阅读:268      评论:0      收藏:0      [点我收藏+]
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {

    ifstream in;
    in.open("test.txt");
    if(!in){
        cout << "open file failed !"<< endl;
        return 1;
    }


//    char ch;
//    // get a char
//    while(in.read(&ch, 1)) {  /// or replace with : in.get(ch)
//        cout << ch << endl;
//    }


    // get a line
    char chr[20];
    while(in.getline(chr, 15)){
        cout << chr <<endl;
    }
    in.close();

    return 0;
}

其他操作可参考:http://www.cnblogs.com/flatfoosie/archive/2010/12/22/1914055.html

C++ 文件读取

原文:http://www.cnblogs.com/lifeinsmile/p/5285250.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!