[問題] 如何輸出到檔案且不覆蓋原本的資料
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
我會使用run 來產生一筆筆GPattern的資料,每當我產生一筆就要輸出到檔案,
但用一般書上的教學方法,輸出會覆蓋掉原先的資料。
因為我會將每一筆輸出的資料編排成新的string,所以似乎沒有辦法先存起來,
最後再一次輸出。
想請問有沒有方法在我的結構下,一次輸出一筆資料到檔案,但不覆蓋原本的資料。
謝謝:)
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
struct GPattern() {
int gid;
....
}
class Example() {
public:
void run(string _filename, unsigned int _minsup);
void PrintGPattern(GPattern&, unsigned int sup);
....
};
Eample::run(string filename, unsigned int minsup) {
for(...) { // some condition
// generate one GPattern, and i want to ouput it
PrintGPattern(gp, sup);
}
}
Example::PrintGPattern(GPattern& gp, unsigned int sup) {
// I want to ouput each GPattern to a .txt file
}
main() {
Example example;
example.run();
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.107.163
→
04/06 16:18, , 1F
04/06 16:18, 1F
→
04/06 16:29, , 2F
04/06 16:29, 2F
→
04/06 17:08, , 3F
04/06 17:08, 3F
→
04/06 17:08, , 4F
04/06 17:08, 4F
推
04/06 17:57, , 5F
04/06 17:57, 5F
推
04/06 19:09, , 6F
04/06 19:09, 6F
推
04/06 20:08, , 7F
04/06 20:08, 7F