c++ 文件操作

来源:互联网 发布:java可变参数不传入 编辑:程序博客网 时间:2024/06/03 19:31

c++ 文件操作

const char*  ReadFile::read_cof(const char* keyword){    memset(this->val,0,sizeof(this->val));    // 格式化字符串(目标字符串,重置数字默认0,重置位置内存大小)    filebuf fb;   // 用于存放文件流位置    if(fb.open("config",ios::in) == NULL) {   //打开文件流(文件名,打开模式)        cout <<"open the config file fieled!!!"<<endl;        return val;     }    istream is(&fb);     //输出流 绑定到文件流    string input;    while(getline(is,input,'\n')){   //读取输出流一行内容(输出流,输出目标string类型,末尾标志默认换行也可为其他)        int pos1 = string::npos;        pos1 = input.find(keyword);       //在目标中查找关键字        if(pos1 != string::npos){            cout <<input.substr(pos1+strlen(keyword) + 1) <<endl;        }        else {            cout <<"find at the EOF";            break;        }    }    fb.close();     //关闭文件流    return val;}
原创粉丝点击