linux讀寫檔案 簡單版

MY CUP OF TEA發表於2021-01-02

程式碼

//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();
}

 

相關文章