本文共 1793 字,大约阅读时间需要 5 分钟。
?C??????????????fopen()???????????????????FILE *fp????????????????
???????\???????????\?????\\????????????????
"r"??????????"w"???????????????????"a"???????????????????????"r+"??????????"w+"??????????????"a+"?????????????????????????????"b"???????"rb"??????????"wb"??????????
??fclose()?????????????????????????????????????????
fgetc()????????????feof()??????fputc()????????????FILE *fp = fopen("file.txt", "r");char ch;while (!feof(fp)) { ch = fgetc(fp); // ????}fclose(fp); fputs()?fprintf()???????????fgets()?????????????fputs()?fprintf()?????fscanf()?fprintf()?????????????
int rollnumber, score;char name[20];FILE *fp = fopen("data.txt", "r");while (!feof(fp)) { fscanf(fp, "%d %s %d", &rollnumber, name, &score);}fclose(fp); rewind()????????????feof()????????fseek()??????????????????????fread()?fwrite()??????????C++?????????????????ifstream???????ofstream???????fstream?????????
??open()????????????
ofstream file;file.open("file.txt", ios::out | ios::app | ios::binary);// ?fstream file("file.txt", ios::out); ??close()???????
ofstream file;file.open("file.txt");// ...??file.close(); <<?>>????????put()?get()?read()?write()???ofstream file("file.bin", ios::out | ios::app);file.put('A');file.close();ifstream file("file.bin", ios::binary);char ch;file.get(ch); ?seekp()?????????write()???????fstream file("file.txt");file.seekg(5, ios::beg); // ????5???string str(10);file >> str; ??????????????????????????????????
转载地址:http://vllx.baihongyu.com/