我試圖用C++在文件Write函數不使用seekp值
所以basicly我
ofstream ofs("file.dat", ios::binary | ios::app);
ofs.seekp(220, ios::beg);
ofs.write((char *)&i, sizeof(i));
但無論我做什麼就寫在一個特定的地方的入口總是寫在文件的末尾。
我想這是關係到iso::app
因爲根據文檔
app (append) Set the stream's position indicator to the end of the stream before each output operation
但是,如果使用吃或沒有它總是會刪除文件的內容。
任何幫助將是巨大的:)
ofstream默認是到ios :: out。添加ios :: in會破壞程序。 –
@Paté:嗯,默認是不相關的,因爲你沒有使用它(你正在使用'ios :: binary ...')。另外,當你說「休息」時,究竟以什麼方式? – NPE
你檢查了錯誤標誌(eofbit,failbit,badbit)嗎? –