我有一個文件需要在運行時多次打開。每次將一些文本添加到文件中。下面是代碼:重複使用流迭代器
ofstream fs;
fs.open(debugfile, fstream::app);
ostream_iterator<double> output(fs, " ");
copy(starting_point.begin(), starting_point.end(), output);
...
fs.open(debugfile, fstream::app);
ostream_iterator<double> output1(fs, " ");
copy(starting_point.begin(), starting_point.end(), output1);
我的問題是,我可以用一個流迭代器「輸出」每次我打開該文件時,如一些方法來清理它?
感謝
爲什麼不把可重用代碼的函數和調用該函數多次? – NathanOliver
那是對的。我可以這樣做。 – colddie