[英]Writing multiple times in model.write() lp file in Gurobi without overwriting the previous content in C++
[英]How can I write to a .csv file multiple times and keep the previous data using C++?
截至目前,我正在這樣做:
std::ofstream file;
file.open("test.csv");
file << "Test case" << std::endl;
file.close()
問題是每次啟動程序時,.csv 文件都會被新數據覆蓋。 所以在這種情況下,每次我運行程序時,我都會得到一行文本"Test case"
而不是將此行添加到 .csv 文件中。 有沒有辦法在每次運行程序時保持數據一致並將它們添加到同一個文件中,同時保留以前的數據?
您可以指定要打開的第二個參數,例如file.open("test.csv", ios_base::app)
。
http://www.cplusplus.com/reference/fstream/ofstream/ofstream/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.