回覆列表
  • 1 # 匠工加工

      使用c語言標準檔案I/O庫中的函式即可。具體來說:

      1、fopen()開啟檔案。

      2、fseek()調整檔案位置。

      3、fwrite()寫入資料。

      4、fclose()關閉開啟的檔案。示例如下,開啟1.txt,並向檔案後面新增hello world的字串。

    #include <stdio.h>

    #include <string.h>

    int main()

    {

    FILE *fp = fopen("1.txt", "a+");

    if (fp==0) { printf("can"t open file\n"); return 0;}

    fseek(fp, 0, SEEK_END);

    char sz_add[] = "hello world\n";

    fwrite(sz_add, strlen(sz_add), 1, fp);

    fclose(fp);

    return 0;

    }

  • 2 # 變餅檔

    在C/C++中,反斜線\是跳脫字元,檔案路徑中反斜線是資料夾分隔符,由於二者之間的不同之處,則必須將資料夾分隔符雙寫,即檔案路徑改為:

    C:\\Users\\狐狸荊\\Desktop\\1.txt

  • 中秋節和大豐收的關聯?
  • 選MPV作家用的話有哪些需要注意的點?