考研資料結構複習筆記 檔案操作

2021-10-11 03:05:15 字數 1643 閱讀 2821

從檔案中讀取資料,內容每行是乙個學生的資訊,包含姓名(不超過10字元)、性別(0:男,1:女)、年齡、班級號(不超過6字元)。要求讀取資料後,找出年齡最小的男生和女生,並存入檔案f.txt

**實現--c語言版

#include #include #include #define n 6

struct student;

void readfromfile(const char *filepath, struct student students)

fclose(f);

}void getmins(struct student students, int *a, int *b)

if(students[i].*** == 1 && famale > students[i].age)

}}void writetofile(const char* filepath, struct student student)

int main()

**實現--c++版

#include #include #include #include #include using namespace std;

class student

student(){}

~student(){}

void gets(stringstream &ss)

void print()

};ifstream& open_file(ifstream &in,const string &file)

vectorreadfile(const string &file)

fin.close();

return students;

}void writefile(const string &file, student s)

void getanswer(const vectorstudents,

int &male_young,

int &famale_young)

if(students[i].*** == 1 && students[i].age < f_min)

}}int main()

c語言檔案操作常用函式:

1. file* fopen(filepath, "mode")

2. fclose(file*)# fclose就是file close

3. int fseek(file *, offset, int whence);

seek_set 從距檔案開頭offset 位移量為新的讀寫位置.

seek_cur 以目前的讀寫位置往後增加offset 個位移量.

seek_end 將讀寫位置指向檔案尾後再增加offset 個位移量. 當whence 值為seek_cur 或

seek_end 時, 引數offset 允許負值的出現.

4. fwrite(&obj, sizeof(type), nums, file*)

5. fread(*buffer, sizeof, count, file*)

6. fprintf(file*, "reg", arguments)

7. fscanf(target, "reg", file*)

考研資料結構複習 陣列(順序結構)

title 考研資料結構複習 subject 陣列 順序結構 author lxfhahaha language c語言 time 2018 10 4 19 25 include include include 用於訪問變長參數列 include define max array dim 8 假設陣...

資料結構操作複習

toc 1.3 2.4 2.3 2.5 1.8刪除節點 int list remove int i while k i 1 if current null current link null del current link current link del link delete del retu...

資料結構複習筆記

資料 資料是資訊的載體,是描述客觀事物屬性的數 字元及所有能輸入到計算機中並被電腦程式識別和處理的符號的集合。資料是電腦程式加工的原料。資料元素 是資料的基本單位,通常作為乙個整體進行考慮和處理。資料項 乙個資料元素可由若干資料項組成,資料項是構成資料元素的不可分割的最小單位。資料物件 是具有相同性...