linux读写文件 简单版

代码

//write
void write_file(const std::string file_name){
    FILE *fp = nullptr;
    fp = fopen(file_name.c_str(),"w+");
    fprintf(fp,"This is testing for mutex\n");
    fclose(fp);
}
//read
void read_file(const std::string file_name){
    std::ifstream fp(file_name,std::ios::binary);
    std::stringstream ss;
    ss << fp.rdbuf();
    std::cout << ss.str() << std::endl;
    fp.close();
}

 

你可能感兴趣的:(C++,C++,c++)