c 中對檔案的一些操作

2021-06-05 07:40:50 字數 1204 閱讀 2998

#include

#include

#include

using namespace std;

int main()

if(!outfile)

int a,b;

int i=0,j=0;

int data[6][2];

while (! myfile.eof() )

myfile.close();

for(int k=0;k

outfile<

cout<

}outfile.close();

return 0;}

複製**

無論讀寫都要包含標頭檔案

讀:從外部檔案中將資料讀到程式中來處理

對於程式來說,是從外部讀入資料,因此定義輸入流,即定義輸入流物件:ifsteam infile,infile就是輸入流物件。

這個物件當中存放即將從檔案讀入的資料流。假設有名字為myfile.txt的檔案,存有兩行數字資料,具體方法:

int a,b;

ifstream infile;

infile.open("myfile.txt");      //注意檔案的路徑

infile>>a>>b;                   //兩行資料可以連續讀出到變數裡

infile.close()

複製**

如果是個很大的多行儲存的文字庫案可以這麼讀:

char buf[1024];                //臨時儲存讀取出來的檔案內容

string message;

ifstream infile;

infile.open("myfile.js");

if(infile.is_open())          //檔案開啟成功,說明曾經寫入過東西

infile.close();}

複製**

寫:將程式中處理後的資料寫到檔案當中

對程式來說是將資料寫出去,即資料離開程式,因此定義輸出流物件ofstream outfile,outfile就是輸出流物件,這個物件用來存放將要寫到檔案當中的資料。具體做法:

ofstream outfile;

outfile.open("myfile.bat");  是存放資料的檔名

if(outfile.is_open())

else

複製**

PHP對檔案的一些操作

alter table guitarwars drop column score 從資料庫中刪除乙個列 add columu新增乙個新列 change column修改一列 modify columu 修改乙個資料表中某一列的資料型別或位置。files 是內建的php超級全域性變數,通過它將一些有用...

對檔案的一些操作2

對檔案的一些操作2 author administrator date 2019 10 29 f open tx1 r encoding utf8 1 按照字元列印 print f.read 5 print f.read 5 print 有個自動換行 一剪梅 紅藕香殘 2 一行一行列印 print ...

python對檔案路徑的一些操作

import glob import os filename list sorted glob.glob r e vs code image png for i in filename list print file format i 檔名 filename os.path.basename i p...