標題是不太清楚,但我的意思是這樣的:使用經C++修改且未關閉的文本文件是否安全?
std::fstream filestream("abc.dat", std::ios::out);
double write_to_file;
while (some_condition) {
write_to_file = 1.345; ///this number will be different in each loop iteration
filestream.seekg(345);
filestream << std::setw(5) << write_to_file << std::flush;
///write the number to replace the number that is written in the previous iteration
system("./Some_app ./abc.dat"); ///open an application in unix,
////which uses "abc.dat" as the input file
}
filestream.close();
那是粗略的想法,每次迭代重新寫號到文件和齊平。我希望不要在每次迭代中打開和關閉文件,以節省計算時間。 (也不知道打開和關閉的複雜性:/)可以這樣做嗎?
./Some_app實際上也是一個讀取但不能更改文件的C++程序 –