C 如何文字檔案寫入1000行後停止寫入並結束程式執行

2022-06-29 07:26:52 字數 1255 閱讀 4221

1樓:匿名使用者

#include

#include

#include

using namespace std;

int main()

;const int count = sizeof(array) / sizeof(int);

ofstream out("stout.txt");

for (int i=0;i<1000&& next_permutation(array, array+count );i++ )

return 0;}

2樓:shiro灬

#include

#include

#include

#include

using namespace std;

int main()

;const int count = sizeof(array) / sizeof(int);

ofstream out("output.txt");

while (next_permutation(array, array+count ))

i++;

copy(array, array+count, ostream_iterator(out, " "));

out << endl;

}return 0;}

c++寫檔案再次執行程式後,之前儲存的檔案的資料就沒有了,如何讓數永久儲存?

3樓:地球軍團

寫檔案時,用fopen( "filename.txt", "a+" ); //檔案以追加的方式開啟,這樣再次執行就不會刪除之前的資料,新的資料追加到後面。

4樓:

檔案是流的一種儲存方式

使用方式如下:

c++寫檔案 再次執行程式後 之前儲存的檔案的資料就沒有了 如何讓數永久儲存 即使再次執行程式也不會消失

5樓:戚文柏

寫檔案時,用fopen( "filename.txt", "a+" ); //檔案以追加的方式開啟,這樣再次執行就不會刪除之前的資料,新的資料追加到後面.

6樓:

估計是程式中開啟檔案用的是建立方式。

在建立方式下,如果檔案已經存在,那就會將其清空。

所以,你要在程式中首先判斷某個名字的檔案是否存在,如果存在就以只讀的方式開啟。

c中,如何在寫入檔案之前將文字檔案清空

覆蓋原檔案 filemode.open 換成filemode.create c 如何在文字檔案中新增資料而不清除原來的內容?從msdn可查到baistreamwriter的構du造函式zhipublic streamwriter 加sw.write translate this.textbox1.t...

C如何對檔案進行讀寫,c 如何讀寫文字檔案

省略些許判斷 如有無該檔案 filestream fs new filestream a.txt filemode.open streamreader sr new streamreader fs 讀取回 string txt sr.readtoend streamwriter sw new str...

Python程式,要求開啟文字檔案,從固定行開始讀取一直讀取某一匹配結果的前一行

實現此功能的 如下 f open xx.txt lines f.readlines f.close l list lines 1 從第二行開始for l in l list if l.find a 1 print l 在沒有找到a之前一直列印else break 如果找到,則跳出迴圈 擴充套件資料 ...