fstream下的读写操作
#include
#include
#include
int main()
{
std::string path = “D/ssss/reflection.hpp”;
//這情況下,默認(rèn)下是std::ios_base::in讀入 trun:在打開時舍棄流的內(nèi)容
std::ifstream open_file(path, std::ios_base::ate | std::ios_base::binary);
std::size_t size = open_file.tellg();
open_file.seekg(std::ios_base::beg);
std::string buffer;
buffer.resize(size);
open_file.read((char*)buffer.c_str(), size);
open_file.close();
std::string write_path = “D:/reflection1.hpp”;
//app:每次寫入,指針移動到末尾,也就是追加 out:寫入,binary:二進(jìn)流模式 trun:在打開時舍棄流的內(nèi)容
std::ofstream write_file(write_path, std::ios_base::binary|std::ios_base::app);
for (int i =0;i<2;i++){
write_file.write(buffer.c_str(), buffer.size());
}
write_file.close();
//默認(rèn)可讀寫模式
//std::fstream fs;
}
總結(jié)
以上是生活随笔為你收集整理的fstream下的读写操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 程序占内存,linux下,一
- 下一篇: mysql tomcat列表增删改查_T